java - Prompting user for input until an empty line -
here main method cypher program.
i'm trying modify code prompts user input until empty line submitted
public static void main(string[] args) { scanner kb = new scanner(system.in); system.out.println("enter "); string message = kb.nextline(); system.out.println("enter encryption key: "); string key = kb.nextline(); int shift = integer.parseint(key); string encrypted = encrpyt(message, shift); system.out.println("encrypted: " + encrypted); string decrypted = decrypt(message, shift); system.out.println("decrypted: " + decrypted); }
just use while loop.
string line = kb.nextline() while (!line.equals("")) { (your code here) line = kb.nextline(); }
the while loop break when user enters empty line.
Comments
Post a Comment