[英]How do I get my java program to output the answer?
I'm new to java and my class has a homework assignment that I need a little help on. 我是java的新手,我的课程有一个家庭作业,需要一点帮助。 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;
}
}
I'm assuming you want the format "Result = a" which would be 我假设您想要的格式为“结果= a”,这将是
System.out.println("Result = " + result);
Or you could use a
since you set them to the same value 或者您可以使用a
因为您将它们设置为相同的值
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);
}
}
You can just use System.out.println("Result: "+result);
您可以只使用System.out.println("Result: "+result);
to print your result
in the console. 在控制台中打印result
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.