CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2013
    Posts
    1

    Unhappy Math Fromula y=x2+6x+5 how to convert to Java Programming code

    Hello
    every one i am new in Java Programming,
    how i need to convert this ( y=x2+6x+5 and second one x2+x3+6x-5 ) to Java Programming code there any one who help me regarding this Problem.

    Thanks alot.

  2. #2
    Join Date
    Sep 2013
    Location
    Nottinghamshire, UK
    Posts
    3

    Re: Math Fromula y=x2+6x+5 how to convert to Java Programming code

    Hello,

    If you're interested in learning Java, I'd recommend TheNewBoston's tutorials (probably the best on YouTube), he covers variables, such as integers (whole numbers) in the fourth video, I hope this is what you're looking for, it is untested but should work for the most part. I've even commented the code for you to read and understand!

    Question 1:

    Code:
    public class Example {
    
        public static final int x = 10; // Creates an integer named X with the value of 10, public means it can be used by any class, static means it can be used in a method and final means you can reassign a value to it.
        public static final int y = x * 2 + 6 * 10 + 5; // Creates an integer named Y with the sum as it's value. public means it can be used by any class, static means it can be used in a method and final means you can reassign a value to it.
    
        public static void main(String[] args) { // Main method, needed for in your main project class file.
            System.out.println("Answer: " + y); // Prints out "Answer: 85" to the console.
        }
    }
    Question 2:

    Code:
    public class Example {
    
        public static final int x = 10; // Creates an integer named X with the value of 10, public means it can be used by any class, static means it can be used in a method and final means you can reassign a value to it.
        public static final int y = x * 2 + x * 3 + 6 * x - 5; // Creates an integer named Y with the sum as its value, public means it can be used by any class, static means it can be used in a method and final means you can reassign a value to it.
    
        public static void main(String[] args) { // Main method, needed in your main project class file.
            System.out.println("Answer: " + y); // Prints out "Answer: 105" to the console.
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured