I am trying to put a password onto this section of code, I am trying to use a do while loop but it carries on looping.
Can you please show me where my errors are? The password I am using is 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);
}
}