Answers for "get input from user"

33

how to take input in java

Scanner sc = new Scanner(System.in);  // 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
System.out.println(userName);//output
Posted by: Guest on May-03-2020
1

how to read input in java

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

Scanner in = new Scanner(System.in); 
while(in.hasNextLine()) {
   String line = in.nextLine();
   System.out.println("Next line is is: " + line); 
}
Posted by: Guest on September-23-2020
0

get input from user

// to get input from user
Scanner.scan= new scanner (System.in);
		// to input some integers
		int myNums =scan.nextInt();
		// to input strings
		String myWords =scan.nextline();
Posted by: Guest on September-26-2021

Browse Popular Code Answers by Language