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

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -