Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Please, tell me what's wrong with this code

import java.util.Scanner; // program uses Class Scanner public class Adrian2 { //main method begins execution of Java application public static void main(String[] args) { // create a Scanner to obtain input from the command windows Scanner input = new Scanner(System.in);

int number1; //first number to add
int number2; // second number to add
int sum;   // sum of number1 and number2

System.out.print("74"); // prompt
number1 = input.nextInt(); // read number1 from the user 

System.out.print("36"); //prompt 
number2 = input.nextInt(); // read number2 from the user



 System.out.println("Sum is 74+36"); // display the sum

} // end method main

} // end Class Adrian2

1 Answer

You are setting a fixed number in your print line command instead of using the vriables (you never use them but instead just printing a string which contains a fixed number)

your code should look like this:

import java.util.*; public class testing {

import java.util.*; public class testing { public static void main(String[] args) {

 Scanner input = new Scanner(System.in); // create a Scanner to obtain input from the command windows

 int number1; //first number to add
 int number2; // second number to add
 int sum;   // sum of number1 and number2

 System.out.print("Enter you first number:"); // Enter a first number message
 number1 = input.nextInt(); // read number1 from the user 

 System.out.print("Enter your second number");  // Enter a second number message
 number2 = input.nextInt(); // read number2 from the user

 sum = number1 + number2;  //add number1 variable to number 2 variable and put it in the sum variable

  System.out.println("Sum is " + sum ); // display the sum message
}

}