学习内容:
if语句
关系运算符
逻辑运算符
break语句
continue语句
重点归纳:
break和continue的用法和区别
break:跳出循环
continue:直接从头开始执行循环内结构,跳过continue后剩余的代码
例题:
解:
点击查看代码
import java.util.Scanner;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()){
int a = sc.nextInt();
int b = sc.nextInt();
if(a != 0 || b != 0){
System.out.println(a + b);
}
else{
break;
}
}
sc.close();
}
}