read integer in java code example
Example 1: read integer input java
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());
Example 2: read int from keyboard java
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scan= new Scanner(System.in);
String text= scan.nextLine();
System.out.println(text);
int num= scan.nextInt();
System.out.println(num);
}
}
Example 3: read int java
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter any number: ");
int num = scan.nextInt();
scan.close();
System.out.println("The number entered by user: "+num);
}
}