2014-10-01 53 views
0

我是新來的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; 
     } 
    } 
+5

'System.out.println(result)'? – 2014-10-01 08:47:17

+0

只是打印結果值,實際上是不打印它只是評估和存儲,但在觀看輸出打印它,因爲它是在上面的評論中提到 – santhosh 2014-10-01 08:50:54

回答

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

我假設你想要的格式「結果= A」,這將是

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

或者你可以使用a因爲你將它們設置爲相同的值

0

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

相關問題