Print Username Program in java

Question:

Jeffy, who is going to complete the higher education this year needs to create a simple application that accepts the name of a person and welcomes them with a message along with their name. She wants to read the data using the class “Scanner”. Implement this scenario using Java.

Sample Input 1:

Enter the name:

Johson

Sample Output 1:

Welcome Johnson.

Sample Input 2:

Enter the name:

Stain Polson

Sample Output 2:

Welcome Stain Polson.

CODE:

import java.util.Scanner;
public class Username
{
    public static void main (String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the name:");
        String name=sc.nextLine();
        System.out.println("Welcome "+name+".");
    }
}

Leave a Comment

Scroll to Top