Reputation: 3
I'm new to java and my class has a homework assignment that I need a little help on. I finished everything except for the output, I can't seem to get the program to produce the answer.
import java.util.Scanner;
public class HomeworkScanner
{
public static void main(String args[])
{
int x, y, z, a, result;
Scanner Keyboard;
Keyboard = new Scanner(System.in);
System.out.println("a = ( x + y ) * z");
System.out.println("Enter first number for x:");
x = Keyboard.nextInt(); //
System.out.println("Enter second number for y:");
y = Keyboard.nextInt(); //
System.out.println("Enter third number for z:");
z = Keyboard.nextInt(); //
result=a=( x + y ) * z;
}
}
Upvotes: 0
Views: 68
Reputation: 1149
import java.util.Scanner;
public class HomeworkScanner
{
public static void main(String args[])
{
int x, y, z, a, result;
Scanner Keyboard;
Keyboard = new Scanner(System.in);
System.out.println("a = ( x + y ) * z");
System.out.println("Enter first number for x:");
x = Keyboard.nextInt(); //
System.out.println("Enter second number for y:");
y = Keyboard.nextInt(); //
System.out.println("Enter third number for z:");
z = Keyboard.nextInt(); //
result=a=( x + y ) * z;
System.out.println("result is :"+result);
}
}
Upvotes: 1
Reputation: 35577
You can just use System.out.println("Result: "+result);
to print your result
in the console.
Upvotes: 0
Reputation: 461
I'm assuming you want the format "Result = a" which would be
System.out.println("Result = " + result);
Or you could use a
since you set them to the same value
Upvotes: 1