循环结构: 1、while循环:先进行条件判断,再执行逻辑代码 初始化:变量初始化 条件判断:只允许返回true或false 循环体:如果条件符合要执行的逻辑代码 迭代变量:促使循环跳出的条件 2、do while循环:先执行逻辑代码,再进行条件判断
以下是个人写的案例:
import java.util.Scanner;
public class qwe {
public static void main(String[]args){
int a =123;
Scanner b =new Scanner(System.in);
while(true){
System.out.println(“请输入密码”);
int c =b.nextInt();
if(c==a){
System.out.println(“密码正确”);
break;
}else {
System.out.println(“密码错误”);
}
}
}
}