create input string java code example

Example 1: how to take input in java

Scanner sc = new Scanner(;  // Create a Scanner object
String userName = sc.nextLine();//read input string
int age = sc.nextInt(); //read input integer
long mobileNo = sc.nextLong(); //read input long
double cgpa = sc.nextDouble(); //read input double

Example 2: how to read input in java

//For continues reading a line
import java.util.Scanner; 

Scanner in = new Scanner(; 
while(in.hasNextLine()) {
   String line = in.nextLine();
   System.out.println("Next line is is: " + line); 


Java Example