Explanation of Solution
Program:
// 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
- Write 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_forwardWhat must be placed on the blank part of the code so that ? will be from ? to ?.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
- How to turn this code that it accepts string input for the choice of drink instead of using int?arrow_forward(textblob.utils Utility Functions) TextBlob’s textblob.utils module offers several utility functions for cleaning up text, including strip_punc and lowerstrip. You call strip_punc with a string and the keyword argument all=True to remove punctuation from the string. You call lowerstrip with a string and the keyword argument all=True to get a string in all lowercase letters with whitespace and punctuation removed. Experiment with each function on Romeo and Julietarrow_forwardPROBLEM STATEMENT: Return the String "odd" if the input is odd otherwisereturn "even". Can you help me with this Java Question.arrow_forward
- Re-type the code and fix any errors. The code should convert non-positive numbers to 1. if (userNum > 0) System.out.print In("Positive."); else System.out.print in("Non-positive, converting to 1."); userNum = 1; System.out.print in("Final: + userNum); Common student error: Changing the order of the lines. You only need to fix the existing code. 1 import java.util.Scanner; 2 3 public class ConvertNegative ( public static void main (String I args) ( Scanner scnr new Scanner(System.in); int userNum; 6. 8. userNum scnr.nextInt(); V* Your solution goes here 11 12 13 } Run View your last submission 479 012marrow_forwardif ( gender == 1 ) System.out.println( "Woman" ); else if ( gender == 1 ) System.out.println( "Man" ); correct the code and and identify the name of error in the a above code?arrow_forwardPlease assist with the attached java question. Thanksarrow_forward
- 2. How do you use "else if" and "else"?arrow_forwardI want to remove words from the user entered string in java. Take the words from the user.arrow_forwardPlease Explain the Steps. (In Java Programming) See expected output below. Create a new Java application called "WeightedAvgDropSmallest" (without the quotation marks) according to the following guidelines. The program prompts the user for five to ten numbers all on one line, separated by spaces, calculates the weighted average of all those numbers except the lowest n numbers, where n and the weight are also given by the user, and displays all the numbers, the weight, the number of lowest numbers dropped, and the calculated average to the user. The program uses methods to: Get the numbers used to calculate the average. Get the number of lowest numbers to drop before calculating the average. Get the weight, a double greater than 0 and less than or equal to 1. Calculate the weighted average of the numbers (except the lowest n numbers) entered by the user. Print the results. 1. The first method should take no arguments and return an array list of doubles. 2. The second method…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