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 Scanner sc = new Scanner(System.in);
String s = sc.next();
int n = sc.nextInt();
double d = sc.nextDouble();
float f = sc.nextFloat();
// more fast way
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine(); // read line
int c = br.read(); // read single charimport java.util.Scanner; // Import the Scanner class
class MyClass {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in); // Create a Scanner object
System.out.println("Enter username");
String userName = myObj.nextLine(); // Read user input
System.out.println("Username is: " + userName); // Output user input
}
}InputUSer Scanner
Also in Java:
- java code to concatinate integer
- countdown timer with seekbar
- how to minimize jframe in java
- multiplication program java
- list in java
- java optional to collection
- creating a program about user asked to enter a number and enters 0 to stop, then calculates the sum of numbers entered, the average, the length of positive numbers and negative numbers entered by the user in java
- java define main function
- how to create a hashmap in java
- java import text file into arraylist
- append to arraylist by index java
- java substring
- copy array in java
- java sort array descending
- jstl core tags
- primitive data types in java
- raspberry stackexchange how to install the java jdk
- how timer class and display to jtextfield w3schools in java
- java arraylist
- how to play an audio in java
- query java persistence
- how to take input in java
- how to set frame colo in java
- simple calculator program in java