
Explanation of Solution
// Import the required package
import java.util.*;
// Class definition
public class Test
{
// Main class definition
public static void main(String[] args)
{
// Invoke the function to print Hello
System.out.print(boxString("Hello"));
}
// Method definition to print the string in a box
public static void boxString(String contents)
{
// Declare the variable to store the length of the string
int n = contents.length();
// Using for loop, Print a line that contains the - character n + 2 times
for (int i = 0; i < n + 2; i++)
{
System.out.print("-");
}
System.out.println();
// Print a line containing the contents, surrounded with a ! to the left and right...

Want to see the full answer?
Check out a sample textbook solution
Chapter 5 Solutions
Big Java Late Objects
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning




