0

How do I ask the user for an input and then store the input for later use?

11th Aug 2016, 3:30 AM
Mauricio Urrego
2 Answers
+ 1
In java you have Scanner Class. you have to create object/instance of Scanner Class and then you can call it's methods to get input from users. ex. Scanner input = new Scanner(System.in); System.out.println("Please enter your age: "); int age = input.nextInt(); // to get integer from user. Like wise you can get all data types
11th Aug 2016, 3:35 AM
AMIT PATEL
AMIT PATEL - avatar
+ 1
If you meant storing it in secondary storage though you can get the input then save it in a txt file. Scanner input = new Scanner(System.in); System.out.println("Please enter your age: "); int age = input.nextInt(); // to get integer from user. try{ PrintWriter writer= new printWriter("location/file.txt"); writer.write(age); writer.close(); }catch(Exception e){ }
11th Aug 2016, 6:51 AM
Nick Nderitu
Nick Nderitu - avatar