how to scan number in java code example
Example 1: how to scan Integer in Java
import java.util.*;
public class HowToScan {
public static void main( String args[] )
{
Scanner S = new Scanner(System.in);
int a;
int b;
int sum;
a = S.nextInt();
b = S.nextInt();
sum = a + b;
System.out.println( a + "+" + b + "=" + sum );
}
}
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);
}
}