密码的输入问题(do while()和st1.equals(st2)的使用)

来源:互联网 发布:nginx访问日志格式 编辑:程序博客网 时间:2024/06/09 22:07

代码:

import java.util.Scanner;
public class p2 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  
   Scanner reader=new Scanner(System.in);
   String st1="1";
   String st2="2";
   do
   {
             System.out.println("请输入密码:");
             st1=reader.nextLine();
             System.out.println("请再次输入密码:");
    st2=reader.nextLine();
    if(!st1.equals(st2)){
     System.out.println("您的密码不一致,请重新输入!");
    }
   }while(!st1.equals(st2));
   System.out.println("设置密码正确");
  
 }

}

答案:


原创粉丝点击