0
How do I ask the user for an input and then store the input for later use?
2 odpowiedzi
+ 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
+ 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){
}