java - Error handling, throw exceptions, and user inputs -
i'm trying to user inputs(eg. file names) , store them arguments in function. however, both println's displayed simultaneously. blocks me entering arguments properly. think has throwing exceptions. cannot run program if don't add exceptions.
public class demon { static scanner input = new scanner(system.in); public static void main(string [] args) throws exception { mainmenu(); }//end main public static void mainmenu() throws exception { system.out.println("welcome demon. please select option below:"); system.out.println("1: encrypt file"); system.out.println("2: decrypt file"); system.out.println("3: exit"); int useroption = input.nextint(); if (useroption == 1) { optionencrypt(); } else if (useroption == 2) { optiondecrypt(); } else if (useroption == 3) { system.exit(0); }else { system.out.println("invalid entry"); system.exit(0); } } public static void optionencrypt() throws exception { system.out.println("enter file name encrypt:"); string inputfilename = input.nextline(); system.out.println("enter file name output:"); string outputfilename = input.nextline(); createencryptionfile("test.txt", "demon.txt"); } output: 1: encrypt file 2: decrypt file 3: exit 1 enter file name encrypt: enter file name output:
just change nextline()
method next()
.
seems when first integer via nextint()
method, there still new line taken nextline()
function
Comments
Post a Comment