Taking Variable Value From User
In this lesson, an explanation of how to store a value in a variable by using input from the user through the keyboard is provided.
We'll cover the following...
Taking user input
We can assign values to variables by means of constants. However, sometimes, we would like the user to input a value for a variable from the keyboard.
See the code given below!
Press + to interact
import java.util.Scanner;class take_input {public static void main(String[] args) {Scanner scanner_one = new Scanner(System.in);System.out.println("Enter your name: ");String name = scanner_one.nextLine();System.out.println("Your name is: " + name);}}
Enter the input below
Understanding the code
One way to ...