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 solutionChapter 5 Solutions
Big Java Late Objects
- Consider the following code. What will be printed out by the code?arrow_forwardWrite an application that reads an integer and determines and prints whether it’s odd or even. [Hint: Use the remainder operator. An even number is a multiple of 2. Any multiple of 2 leaves a remainder of 0 when divided by 2.]arrow_forward(Number of days in a year) Write a method that returns the number of days in a year using the following header: public static int numberOfDaysInAYear(int year)Write a test program that displays the number of days in year from 2000 to 2020.arrow_forward
- Do not run. Explain the output of the code. Only correct answer will be upvoted else downvoted.arrow_forwardQ1) Write a method that checks whether two words are anagrams. Two words are anagrams if they contain the same letters in any order. For example, "silent" and "listen" are anagrams. Write a test program that prompts the user to enter two strings and, if they are anagrams, displays "anagram", otherwise displays "not anagram". Note: The header of the method is as follows: public static boolean isAnagram(String s1, String s2) Sample Input #1: Enter two strings: Silent listen Sample Output #1: The string “Silent” and “listen” are anagrams. Sample Input #1: Enter two strings: teach peach Sample Output #1: The string “teach” and “peach” aren’t anagrams.arrow_forwardwrite legibly.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education