5.16 *zyLab: Hello IDE The goal of this problem is learn how to use Eclipse or IntelliJ. Submit the source code files (.java) below. Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct. Complete the following: In your chosen IDE, create a new project. You can name the project anything you like, we recommend "M5". Create a new class file, titled HelloIDE (which will create the file HelloIDE.java). Write a main method in this class that prompts a user for their name, and then replies with "Hello, ___!" filling in the blank with the typed in name, trimmed. Otherwise, if the string is empty, or just contains only whitespace, or if no input is given, output "Hello, stranger!". Example input/output for input "Mark":

Answer :

frknkrtrn

Answer:

import java.util.Scanner;

public class HelloIDE

{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

   

 System.out.print("Enter your name: ");

 String name = input.nextLine();

 

 name = name.trim();

 

 if(name.equals(""))

     name = "stranger";

     

 System.out.println("Hello, " + name + "!");

}

}

Explanation:

import the Scanner class to be able to get input from the user

Create an object of the Scanner class called input

Ask the user to enter the name and set it to the name

Trim the name using trim() method, removes the whitespaces from the string

Check the name. If name is equal to "", set the name as stranger. This way if the name is empty, or just contains whitespaces or if name is not given, name will be set as stranger.

Print the name in required format

Other Questions