计算a+b的和
每行包行两个整数a和b
对于每行输入对应输出一行a和b的和
输入
1 5
输出
每行包行两个整数a和b
对于每行输入对应输出一行a和b的和
输入
1 5
输出
6
题目解答
import java.util.*;
public class Main
{
public static void main(String srgs[])
{
int a,b;
Scanner input = new Scanner(System.in);
while(input.hasNext()) //检查输入的是否是数字 不是则跳过循环
{
a= input.nextInt();
b= input.nextInt();
System.out.println(a+b);
}
}
}
查找到网上的另一个例子
public
class
Test {
public
static
void
main(String args[]){
Scanner input =
new
Scanner(System.in);
System.out.println(
"请输入一个数"
);
//1.输入非数字abc
int
age =
0
;
while
(
true
) {
if
(input.hasNextInt() ==
true
) {/
2
./检查是否是数字,结果不是,跳过
if
语句块
age = input.nextInt();
System.out.println(
"true"
);
}
else
{
//3.执行打印操作,关键问题来,系统把false当做System.in读进来了,所以就跟1一样咯
System.out.println(
"false"
);
}
}
}
}