【发布时间】:2020-04-22 07:03:50
【问题描述】:
所以基本上我想弄清楚如何使用Integer.valueOf(String s) 或Integer.parseInt(String s) 通过为用户输入键入“end”来停止这个程序
import java.util.Scanner;
public class monkey1{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int sum = 0;
int lol = 1;
do {
System.out.print("Enter a number: ");
lol = s.nextInt();
sum += lol;
if (lol > 0) {
System.out.println("Sum is now: " + sum);
}
} while (lol>0);
}
}
【问题讨论】:
标签: java if-statement while-loop