【发布时间】:2018-03-22 18:11:08
【问题描述】:
如果输入不是数字并且我无法弄清楚,我正在尝试使其成为可能会抛出我的异常,有人可以帮助我走上正确的轨道
import java.util.Scanner;
class calculations
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int number;
int total = 0;
try
{
} catch ( IllegalArgumentException e)
{
//error
}
while (true)
{
number = scan.nextInt();
if (number == 0)
{
break;
}
total += number;
}
System.out.println("Total is " + total);
}
}
【问题讨论】:
-
你在抓
IllegalArgumentException而不是扔它 -
定义“数字”。
-
为什么你认为
try...catch块会这样做? -
整数或任何数字,即浮点数?
标签: java