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 USE JAVA
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started