summaryrefslogtreecommitdiffstats
path: root/Java/HollowBox.java
blob: 64bb43d3f63996fc975af8793a34391a310a848c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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