In programming we need to accept user inputs process them and provide result.We use Scanner class to get user input.
In this part of tutorial we will accept a message from user and print it using print condition.
Java scanner :
Initializing a java String variable for accepting user input
public static String message;
then initialize Scanner object to parse input
Scanner scan = new Scanner(System.in);
using this object we need to accept value and store in String variable with the help of nextLine() method.
message = scan.nextLine();
then print the message variable
System.out.println(message);
public static String message; public static void main(String args[]) { Scanner scan = new Scanner(System.in); message = scan.nextLine(); System.out.println(message); }
If you have any query in this tutorial on java scanner let us know in the comment section below.
Do like and share this tutorial for more interesting tutorials.