Question: My code is shown above. For this assignment, you are supposed to ask the user what their name is. Also if the user just presses

 My code is shown above. For this assignment, you are supposed

My code is shown above.

For this assignment, you are supposed to ask the user what their name is. Also if the user just presses enter and doesnt type anything you are supposed to re prompt the user saying "Please enter your name?". When I run the program and press enter after "What is your name?" it just prints "Hello, !".

What am I doing wrong here and how can I fix it? Any help greatly appreciated

import java.util.Scanner; public class PersonalizedHelloWorld public static void main(String[] args)f Scanner sc- new Scanner(System.in); String name- getName (sc); System.out.println("Hello, "+name+"!); public static String getName (Scanner sc)t //helper System.out.print ("What is your name? "); String name-sc.nextLine(); while(name-"") System.out.print("Please enter your name? "); name-sc.nextLine(); return name

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!