The following is how to properly use the java.util.Scanner class to interactively read user input from System.in correctly( sometimes referred to as stdin, especially in C, C++ and other languages as well as in Unix and Linux). It idiomatically demonstrates the most common things that are requested to be done.
The Scanner class is used to read Java user input. Scanner is part of the java.util package, so it can be imported without downloading any external libraries. Scanner reads text from standard input and returns it to a program. Once the Scanner class is imported into the Java program, you can use it to read the input of various data types. Depending on whether you want to read the input from standard input and output
Code Snippet
//Scanner Class in Java
import java.util.Scanner;
public class App {
public static void main(String[] args) {
// a2+b2+2ab
Scanner in = new Scanner(System.in);
int a, b, c;
System.out.println("Enter 2 Nos : ");
a = in.nextInt();
b = in.nextInt();
c = (a * a) + (b * b) + (2 * a * b);
System.out.println("Result : " + c);
// ! --------------------------------
float a1, b1, c1;
System.out.println("Enter 2 Nos : ");
a1 = in.nextFloat();
b1 = in.nextFloat();
c1 = (a1 * a1) + (b1 * b1) + (2 * a1 * b1);
System.out.println("Result : " + c1);
}
}
/*
* in.nextInt();
* in.nextFloat();
* in.nextDouble();
* in.next(); => word
* in.nextLine(); => Line
*/
// javap java.util.Scanner => Check more info from Java Package