用do while语句写一个程序
题目为:输入密码直到正确

解决方案 »

  1.   

    假设100的为争取的密码
    int password=0;
    do{
    password++;
    }while(password==100)
    system.out.prinln("密码正确")
    其实看到这个条件后很晕,给的要求太少了
      

  2.   

    2楼你给的是个啥啊?供参考:String correct = "123456";
    Scanner sc = new Scanner(System.in);
    while (true) {
      String inp = sc.nextLine();
      if (corrent.equals(inp)) break;
      System.out.println("Wrong");
    }
    System.out.println("Correct");
      

  3.   

    谢谢啦!可以给我一些学JAVA的建议吗?
      

  4.   

    System.out.println("请输入密码!");
         byte[] bytes = new byte[1024];
         InputStream i;
         String str;
         do
         {
         i = System.in;
         int m = i.read(bytes);
         str = new String(bytes, 0, m);
         if(str.equals("passwd\r\n")){
         System.out.println("欢迎登陆!");
         break;
         }else{
         System.out.println("密码错误");
         }
         }
         while(str!=null && !str.equals(""));