Question: Assume we have already defined a variable of type String called name with the following line of code: String name = ???; // 'name' can

Assume we have already defined a variable of type String called name with the following line of code:

String name = "???"; // 'name' can have any String value

TASK: Print a welcome message "Hello, name! Welcome to CS 7! :)" surrounded by a box of asterisks (*) with spaces separating the box and your text.

EXAMPLE: If name is "Newman", you would print the following:

************************************** * * * Hello, Newman! Welcome to CS 7! :) * * * **************************************

EXAMPLE: If name was "Jerry", you would print the following:

************************************* * * * Hello, Jerry! Welcome to CS 7! :) * * * *************************************

NOTE: Notice how the length of name affects the length of the message, which in turn affects the number of surrounding asterisks and spaces.

NOTE: You do not need to create a class or main method, and you do not need to create the variable name. We have done all of that behind the scenes.

HINT: Try to re-use your code from the previous two problems! Figure out how many asterisks go on the 1st/5th rows, and figure out how many spaces go on the 2nd/4th rows.

Sample Input 1:

Frodo

Sample Output 1:

************************************* * * * Hello, Frodo! Welcome to CS 7! :) * * * *************************************

Sample Input 2:

Sam

Sample Output 2:

*********************************** * * * Hello, Sam! Welcome to CS 7! :) * * * ***********************************

PLEASE ANSWER IN JAVA

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!