In: Computer Science
Write a Java program that reads a name and displays on the screen.
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
//importing required package
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
//Scanner is used to take input from the user
//creating Scanner Object
Scanner scnr = new Scanner(System.in);
System.out.print("Enter Name:");
//getting string input from the user using Scanner
object
String name = scnr.nextLine();
//printing the name
System.out.println("Name:
"+name);
}
}
//code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!