TYBBA(CA) Core Java Slip No 13 Q B

Q.Write a java program that asks the user name, and then greets the user by name. Before outputting the user’s name, convert it to upper case letters. For example, if the user’s name is Raj, then the program should respond “Hello, RAJ, nice to meet you!”. [25 M]

import java.util.Scanner;

public class GreetUser {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        // Accept user name
        System.out.print("Enter your name: ");
        String name = sc.nextLine();

        // Convert to uppercase
        String upperName = name.toUpperCase();

        // Display greeting
        System.out.println("Hello, " + upperName + ", nice to meet you!");

        sc.close();
    }
}
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top