diff options
Diffstat (limited to 'Java/HollowBox.java')
-rw-r--r-- | Java/HollowBox.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Java/HollowBox.java b/Java/HollowBox.java new file mode 100644 index 0000000..64bb43d --- /dev/null +++ b/Java/HollowBox.java @@ -0,0 +1,52 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class HollowBox { + public static void main(String[] args) throws java.io.IOException { + int h,w; + //Buffered readers can improve speed up to 30% as they are less bloated than scanners and don't cause a memory leak when not closed + BufferedReader HeightI = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader WidthI = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Height"); + h = Integer.parseInt(HeightI.readLine()); + System.out.println("Width"); + w = Integer.parseInt(WidthI.readLine()); + + +//if less than 3, re-enter +if(h<3) { +System.out.println("Invalid height! Re-enter:"); +h = Integer.parseInt(HeightI.readLine()); + +} + +if(w<3) { +System.out.println("Invalid width! Re-enter:"); +w = Integer.parseInt(WidthI.readLine());; +} + + +for(int i=0;i<h;i++) { //loops for height +for(int j=0;j<w;j++) { //loops for width + +if(i==0||i==h-1) { //if i is in the 0th place or height then it will print out * +System.out.print("*"); +}else { +if(j==0||j==w-1) { //if j is in the 0th place or width then it will print out * +System.out.print("*"); +}else { +System.out.print(" "); //if j is in the in between the 0th place and width then it will print out a space +} +} +} + +System.out.println(""); //prints out next line +} + +} + +} + + + +//By msglm; Special thanks to Jude Spikes |