import java.util.*;
public class Revision {
static int[] num = new int[3];
static int i ;
static int sum;
public static void main(String arg[]) {
System.out.print("Enter the 4 numbers");
Scanner sc=new Scanner(System.in);
sum=sc.nextInt();
for(i=0; i<num.length; i++) {
sum=sum + num[i];
}
}
System.out.print("Sum=" + sum);
}
问问题
47 次
1 回答
0
这是你想要的 ?
import java.util.*;
public class Revision {
static int NO_LIMIT = 4;
static int[] num = new int[NO_LIMIT];
static int i ;
static int sum;
public static void main(String arg[]) {
Scanner sc=new Scanner(System.in);
int count = 0;
while(count < NO_LIMIT){
System.out.print("Enter the number" + (count+1) +":");
num[count] = sc.nextInt();
count ++;
}
for(i=0; i<num.length; i++) {
sum=sum + num[i];
}
System.out.print("Sum=" + sum);
}
}
于 2012-10-25T06:04:39.843 回答