+ 3
How can i get a user input in my program?
how it is work?
4 Answers
+ 12
public class Program
{
public static void main(String[] args) {
int num = new java.util.Scanner(System.in).nextInt(); //used for inputting
System.out.println(num);
}
}
explained in the java course
+ 4
import java. util. Scanner;/*import pkg of scanner*\
Scanner sc= new Scanner(System.in);/*object of scanner *\
x=sc.nextInt();/*for take input*\
+ 1
Better use Scanner or Buffered Reader. Here are some examples.
Scanner:
https://code.sololearn.com/cr62Dl7fsMDv/?ref=app
Buffered Reader:
https://code.sololearn.com/crLzBq1OHLpQ/?ref=app
+ 1
there are several ways to achieve this
like you can use the scanner method
or use
string x=JOptionpane.showInputDialog("your message");