如何让我的java程序输出答案?

时间:2014-10-01 08:45:33

标签: java

我是java的新手,我的班级有一个家庭作业,我需要一些帮助。我完成了除输出之外的一切,我似乎无法得到程序来产生答案。

    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;
         }
    }

3 个答案:

答案 0 :(得分:1)

我假设你想要格式为“Result = a”,这将是

System.out.println("Result = " + result);

或者您可以使用a,因为您将它们设置为相同的值

答案 1 :(得分:1)

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);
     }
}

答案 2 :(得分:0)

您可以使用System.out.println("Result: "+result);在控制台中打印result