如何使用while循环

用户2932824

我正在尝试在此部分代码中输入密码,我正在尝试使用do while循环,但它会进行循环。

您能告诉我我的错误在哪里吗?我使用的密码是1234

import javax.swing.*;

public class cipherprac
{                    
  static int choice = 0;
  public static String msg;
  public static int password = 1234;
  public static int response = 0;

  public static void main (String[] args)
  {
    msg = JOptionPane.showInputDialog("Enter the message");
    response = Integer.parseInt(JOptionPane.showInputDialog("Enter the password"));
    do
    {
      char enc;
      String encmsg = "";
      int len = msg.length();
      for (int i = 0; i < len; i++) 
      {
        char cur = msg.charAt(i);
        int val = (int) cur;
        val = val - 30;
        enc = (char) val;
        encmsg = encmsg + enc;  
        msg = encmsg;    
      }
    }
    while(response == password) ;      

    JOptionPane.showMessageDialog(null, " " + msg);
  }
}

您无需在代码中更改response(nor password),因此,如果将其设置为,1234则它将永远循环。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章