- 1
how to read the input from user...?
explain the all ways to read the input. Thanx in advance.
2 Answers
+ 3
By use scanner like this code .
Above and outside the class write
import java.util.Scanner; âš
Then inside the main method write
Scanner input = new Scanner (System.in);
int x = input.nextInt ();
System.out.println(x);
> this program for read integer number from user then store it in x variable after that print x
* if you want to enter others like string use this statement :
String s = input.nextLine();
+ 1
Some options create a obj Scanner or use JOptionPane