首页 > 代码库 > 啦啦啦
啦啦啦
1.while循环结构
public class Demo{
public static void main(String [] args){
int sum =0; //当前数之和
int num =1; //家数
while(num<=100){
sum =sum+num; //累加
num =num+1;
System.out.pritnln("100以内的数字之和为:"+sum);
}
}
2.do-while结构循环
import java.util.Scanner;
public class Demo{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
String answer = " ";
do{
System.out.println("上级编写程序");
System.out.print("合格了吗?(y/n)");
answer=input.next();
System.out.pritnln(" ");
}while (!"y".equsls(answer));
System.out.pritnln("恭喜你通过了测试!");
}
}
啦啦啦