我似乎无法弄清楚如何在 for 循环中添加值。我应该得到这样的输出:
How many numbers? 3 //user inputs numbers desired. number please 1 2 3 Total is 6
任何帮助将不胜感激!
import java.util.Scanner ;
public class AddNumbers {
public static void main(String[] args) {
int sum = 0;
int count = 1;
Scanner scan = new Scanner(System.in);
System.out.println("How many numbers?");
int n = scan.nextInt();
for(int i=0; i <= n; i++){
System.out.println ("number please");
int c = scan.nextInt();
//stuck
}
System.out.println("Total is " + sum);
}
}