how to take integer input from user in java code example
Example 1: how to take input in java
Scanner sc = new Scanner(System.in);
String userName = sc.nextLine();
int age = sc.nextInt();
long mobileNo = sc.nextLong();
double cgpa = sc.nextDouble();
System.out.println(userName);
Example 2: read integer input java
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());
Example 3: 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);
}
}