Hollow Box

Hollow Box

Write an application program that will draw a hollow box (a box with empty space in between). The program will ask the user to key in a whole number larger or equals to 5. An error message would appear if the user keys in a number less than 5. The program should only exit if the user chooses to exit. For example, if the user keys in 8, the hollow box (of length and width of 8 characters) should be as follows :

88888888 88888888 88 88 88 88 88 88 88 88 88888888 88888888

The walls of the box are fixed at 2 layers. Hence, another example, if the user keys in 7, the hollow box (of length and width of 7 characters) should be as follows :

7777777 7777777 77 77 77 77 77 77 7777777 7777777

Provide a tester class to test the implementation of your solution. Writing the entire program in a single Class is not allowed.

View Answers

October 28, 2010 at 4:07 PM

Hello Friend,

Try this:

import java.util.*;
class Box{
public void check(Scanner input,int key){
if(key<5){
    System.out.println("Error!Enter another key (>=5): ");
    key=input.nextInt();
    }
    for(int i=1;i<=2;i++){
        for(int j=1;j<=key;j++){
            System.out.print(key);
        }
        System.out.print(" ");
    }
    int n=key-4;
    int c=n*2;
    for(int i=1;i<=c;i++){
    for(int j=1;j<=2;j++){
        System.out.print(key);
    }
    System.out.print(" ");
}
for(int i=1;i<=2;i++){
        for(int j=1;j<=key;j++){
            System.out.print(key);
        }
        System.out.print(" ");
    }
}
}
public class HollowBox{
public static void main(String[] args){
    Box b=new Box();
    Scanner input=new Scanner(System.in);
    int menu = 0;
System.out.println("Choose Option");
System.out.println("1. Draw");
System.out.println("2. Exit");
boolean quit = false;
do{
System.out.println();
System.out.print("Please enter your choice: ");
menu = input.nextInt();
System.out.println();

    switch(menu) {
case 1:
    System.out.println("Enter key (>=5): ");
    int key=input.nextInt();
    b.check(input,key);
    break;
case 2:
    quit = true;
    break;
     }
    }
    while (!quit);
}
}

Thanks


November 2, 2010 at 8:03 PM

thx so much buddy.... so helpfull ^^









Related Tutorials/Questions & Answers:
Hollow Box
Hollow Box  Write an application program that will draw a hollow box... to exit. For example, if the user keys in 8, the hollow box (of length and width..., another example, if the user keys in 7, the hollow box (of length and width
printing hollow square
printing hollow square  Write an application (PrintingSquares.java) that prompts the user to enter the size of the side of a square, then displays a hollow square of that size made of asterisks. Your program should work
Advertisements
ModuleNotFoundError: No module named 'box-box'
ModuleNotFoundError: No module named 'box-box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'box-box' How to remove the ModuleNotFoundError: No module named 'box-box
ModuleNotFoundError: No module named 'box-box'
ModuleNotFoundError: No module named 'box-box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'box-box' How to remove the ModuleNotFoundError: No module named 'box-box
HTML in the box
HTML in the box  Can I use any HTML in the box
input box
input box  give me the code of input box in core java
input box
input box  give me the code of input box in core java
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
com.netflix.hollow - hollow version 2.11.0 Maven dependency. How to use hollow version 2.11.0 in pom.xml?
com.netflix.hollow  - Version 2.11.0 of hollow Maven dependency? How to use  com.netflix.hollow  - Version 2.11.0 of hollow in pom.xml? How to use hollow version 2.11.0 in pom.xml? Learn to use this dependency in your
com.netflix.hollow - hollow version 2.8.7 Maven dependency. How to use hollow version 2.8.7 in pom.xml?
com.netflix.hollow  - Version 2.8.7 of hollow Maven dependency? How to use  com.netflix.hollow  - Version 2.8.7 of hollow in pom.xml? How to use hollow version 2.8.7 in pom.xml? Learn to use this dependency in your
com.netflix.hollow - hollow version 2.0.0 Maven dependency. How to use hollow version 2.0.0 in pom.xml?
com.netflix.hollow  - Version 2.0.0 of hollow Maven dependency? How to use  com.netflix.hollow  - Version 2.0.0 of hollow in pom.xml? How to use hollow version 2.0.0 in pom.xml? Learn to use this dependency in your
com.netflix.hollow - hollow version 2.6.8 Maven dependency. How to use hollow version 2.6.8 in pom.xml?
com.netflix.hollow  - Version 2.6.8 of hollow Maven dependency? How to use  com.netflix.hollow  - Version 2.6.8 of hollow in pom.xml? How to use hollow version 2.6.8 in pom.xml? Learn to use this dependency in your
com.netflix.hollow - hollow version 4.2.3 Maven dependency. How to use hollow version 4.2.3 in pom.xml?
com.netflix.hollow  - Version 4.2.3 of hollow Maven dependency? How to use  com.netflix.hollow  - Version 4.2.3 of hollow in pom.xml? How to use hollow version 4.2.3 in pom.xml? Learn to use this dependency in your
dropdown box
dropdown box  i need to have country,state and city in drop down box using ajax and use db2 database   Have a look at the following link: JSP dependent dropdown
dialog box
dialog box to ask to quit or continue  hello. write an application that displays a series of at least four interview questions and each question... of the interview, use a dialog box to ask whether the user wants to - enter another set
dialog box
dialog box to show latest question  hello. write an application that displays a series of at least four interview questions and each question should... of the interview, use a dialog box to ask whether the user wants to - enter another set
combo box
combo box  Hi, [_|] dropdown box [ ] [INCLUDE... a screen like this using jsp-servlet(or DAO,DTO),in that drop down box i should get
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
. at the end of the interview, use a dialog box to ask whether the user wants
dialog box
of the interview, use a dialog box to ask whether the user wants to - enter another set
dialog box
. at the end of the interview, use a dialog box to ask whether the user wants
Maven Repository/Dependency: com.netflix.hollow | hollow
Maven Repository/Dependency of Group ID com.netflix.hollow and Artifact ID hollow. Latest version of com.netflix.hollow:hollow dependencies. # Version Release Date 1 7.8.0
How to create a confirmation box?
How to create a confirmation box?  How to create a confirmation box
How to create an input box?
How to create an input box?  How to create an input box
What is a prompt box?
What is a prompt box?  What is a prompt box
com.netflix.hollow - hollow-ui-tools version 2.9.6 Maven dependency. How to use hollow-ui-tools version 2.9.6 in pom.xml?
com.netflix.hollow  - Version 2.9.6 of hollow-ui-tools Maven dependency? How to use  com.netflix.hollow  - Version 2.9.6 of hollow-ui-tools in pom.xml? How to use hollow-ui-tools version 2.9.6 in pom.xml? Learn to use
com.netflix.hollow - hollow-ui-tools version 4.6.1 Maven dependency. How to use hollow-ui-tools version 4.6.1 in pom.xml?
com.netflix.hollow  - Version 4.6.1 of hollow-ui-tools Maven dependency? How to use  com.netflix.hollow  - Version 4.6.1 of hollow-ui-tools in pom.xml? How to use hollow-ui-tools version 4.6.1 in pom.xml? Learn to use
com.netflix.hollow - hollow-ui-tools version 2.6.5 Maven dependency. How to use hollow-ui-tools version 2.6.5 in pom.xml?
com.netflix.hollow  - Version 2.6.5 of hollow-ui-tools Maven dependency? How to use  com.netflix.hollow  - Version 2.6.5 of hollow-ui-tools in pom.xml? How to use hollow-ui-tools version 2.6.5 in pom.xml? Learn to use
com.netflix.hollow - hollow-ui-tools version 2.8.4 Maven dependency. How to use hollow-ui-tools version 2.8.4 in pom.xml?
com.netflix.hollow  - Version 2.8.4 of hollow-ui-tools Maven dependency? How to use  com.netflix.hollow  - Version 2.8.4 of hollow-ui-tools in pom.xml? How to use hollow-ui-tools version 2.8.4 in pom.xml? Learn to use
box +15
box +15  i want help to complete this program. import java.util.*; class Mgic2{ public static void main(String []args){ Random r=new Random(); int [][] magic=new int[3][3]; boolean v15=true; while(v15){ int
javascript confirm box
javascript confirm box  javascript confirm box
check box left justification
check box left justification  how to make a check box left justification which is at right end? thanks in advance
combo box - JSP-Servlet
combo box  how to get a combo box in jsp page which allows editing as well as list box
autosuggest box - Ajax
autosuggest box Java example  How to implement auto suggest box using Ajax-DWR technology in jsp/html
Text box Checking
Text box Checking  I want to Write only the word A-Z in a text box What is the code
populate Combo Box dynamically
populate Combo Box dynamically  Hi, How to populate the Combo Box dynamically using Flex with Jsp's
how to insert check box
how to insert check box   how to insert check box into jtable row in swing
Maven dependency for com.netflix.hollow - hollow version 6.5.0 is released. Learn to use hollow version 6.5.0 in Maven based Java projects
Maven dependency for  com.netflix.hollow  - Version 6.5.0 of hollow released The developers of   com.netflix.hollow - hollow project have... version of  com.netflix.hollow - hollow library is 6.5.0. Developer can use
Maven dependency for com.netflix.hollow - hollow version 7.1.6 is released. Learn to use hollow version 7.1.6 in Maven based Java projects
Maven dependency for  com.netflix.hollow  - Version 7.1.6 of hollow released The developers of   com.netflix.hollow - hollow project have... version of  com.netflix.hollow - hollow library is 7.1.6. Developer can use
Maven dependency for com.netflix.hollow - hollow version 7.1.0 is released. Learn to use hollow version 7.1.0 in Maven based Java projects
Maven dependency for  com.netflix.hollow  - Version 7.1.0 of hollow released The developers of   com.netflix.hollow - hollow project have... version of  com.netflix.hollow - hollow library is 7.1.0. Developer can use
Maven dependency for com.netflix.hollow - hollow version 2.10.0 is released. Learn to use hollow version 2.10.0 in Maven based Java projects
Maven dependency for  com.netflix.hollow  - Version 2.10.0 of hollow released The developers of   com.netflix.hollow - hollow project... version of  com.netflix.hollow - hollow library is 2.10.0. Developer can use
Maven dependency for com.netflix.hollow - hollow version 3.4.0 is released. Learn to use hollow version 3.4.0 in Maven based Java projects
Maven dependency for  com.netflix.hollow  - Version 3.4.0 of hollow released The developers of   com.netflix.hollow - hollow project have... version of  com.netflix.hollow - hollow library is 3.4.0. Developer can use
Maven dependency for com.netflix.hollow - hollow version 6.4.1 is released. Learn to use hollow version 6.4.1 in Maven based Java projects
Maven dependency for  com.netflix.hollow  - Version 6.4.1 of hollow released The developers of   com.netflix.hollow - hollow project have... version of  com.netflix.hollow - hollow library is 6.4.1. Developer can use
Maven dependency for com.netflix.hollow - hollow version 2.9.4 is released. Learn to use hollow version 2.9.4 in Maven based Java projects
Maven dependency for  com.netflix.hollow  - Version 2.9.4 of hollow released The developers of   com.netflix.hollow - hollow project have... version of  com.netflix.hollow - hollow library is 2.9.4. Developer can use
Maven dependency for com.netflix.hollow - hollow version 6.3.2 is released. Learn to use hollow version 6.3.2 in Maven based Java projects
Maven dependency for  com.netflix.hollow  - Version 6.3.2 of hollow released The developers of   com.netflix.hollow - hollow project have... version of  com.netflix.hollow - hollow library is 6.3.2. Developer can use

Ads