public static void game2(){
//游戏2:让用户输入两个数字,你来计算出这两个数字间的所有整数和
Scanner sc = new Scanner(System.in);
System.out.println("请输入两个整数:");
int m = sc.nextInt();
int n = sc.nextInt();
int sum = 0;
if (m>n) {
int temp = m;
m = n;
n = temp;
}else if (m==n) {
System.out.println(0);
}else {
int x = m+1;
while (x<n) {
sum += x;
x++;
}
System.out.println(sum);
}
}作者: 石少星@ 时间: 2015-8-25 19:44
public static void game2() {
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数字");
int i = sc.nextInt();
System.out.println("请输入第二个数字");
int j = sc.nextInt();
int sum = 0;
for (int x=(i<j?i:j);x<=(i>j?i:j);x++) {
sum += x;
}
System.out.println(sum);