Java Inputs
You can already show the data to the users.
Now let's receive it from user.
In java reading the input is a bit complicated
We have a Scanner class in java
the Scanner class have methods to read different type of input.
There are some of it that we use frequently
nextLineread the whole input line until found a line separator delimiter.nextread the input until found a blank space (Space bar key)nextIntread the input as an IntegernextDoubleread the input as a floating point number
read more here
You have to use the Scanner class as show here
import java.util.Scanner;
public class LearnInput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name: ");
String name = sc.nextLine();
System.out.println("Enter your age: ");
int age = sc.nextInt();
System.out.println("Enter your salary: ");
double salary = sc.nextDouble();
System.out.println("Your name is " + name);
System.out.println("Your age is " + age);
System.out.println("Your salary is " + salary);
sc.close();
}
}
first import Scanner class
//Then Codedeclare Explanationa new Scanner object (Here is named sc)
FirstMake we import the sure to use java.util.Scannerit.the right data type to the right scanner method
Line 5 : We create a Scanner variable