程序非常簡單,它是自我分配的,所以不,它不是作業。變量結果未找到
用戶應該輸入三個數字,顯示平方的數字,並顯示數字的總和。
import java.util.Scanner;
public class CompSquares {
public static void main (String args[]) {
Scanner s= new Scanner(System.in);
int num1;
System.out.println(" Enter a number please.");
num1 = s.nextInt();
int num2;
System.out.println("One more.");
num2 = s.nextInt();
int num3;
System.out.println("Last one.");
num3 = s.nextInt();
System.out.println("The numbers squared are " + Square(num1, num2, num3));
System.out.println("The sum of these numbers is " + Sum(result));
}
private static double Square (int num1, int num2, int num3) {
if (num1 > 0) {
num1 *= num1;
System.out.println (num1);}
else {
System.out.println("Enter a correct number, please.");
}
if (num2 > 0){
num2 *= num2;
System.out.println (num2); }
else {
System.out.println("Really? Again. Do the right thing this time, jeez.");
}
if (num3 > 0){
num3*=num3;
System.out.println (num3);}
else {
System.out.println("Just make it more then one!!");
}
}
public static int Sum (int num1, int num2, int num3, int result) {
result = num1 + num2 + num3;
System.out.println(result);
}
}
總和需要這個aruments(int num1,int num2,int num3,int結果)並且你只傳遞結果,第二個:你的主結果中沒有結果變量的結果 –