In: Computer Science
OOOOOOOO
OOOOOOOO
OO OO
OO OO
OOOOOOOO
OOOOOOOO
*
**
***
**
*
*
**
***
****
*****
****
***
**
*
And so on…
(Hint: you will need two for-loops in a for-loop)
import java.util.*;
public class Solution {
// printBox method
static void printBox() {
for(int i=0; i<6; i++) {
for(int j=0;
j<8; j++) {
if((i==2 && j>1 && j<6) ||
(i==3 && j>1 && j<6)) // Check the
condition
System.out.print(" ");
else
System.out.print(" O ");
}
System.out.println(); // For enter the new line.
}
}
// printArrow method taking arrowSize as a parameter
static void printArrow(int arrowSize) {
int i=0, j=0, k=0, l=1;
for(i=0; i<arrowSize*2; i++) {
// Outer loop
if(i<=arrowSize) {
for(j=0; j<i; j++) { // Inner loop
System.out.print("* ");
}
System.out.println();
}else {
for(k=0; k<arrowSize-l; k++) { // Inner
loop
System.out.print("* ");
}
l++;
System.out.println(); // For enter the new
line.
}
}
}
public static void main(String[] args) {
Scanner scan = new
Scanner(System.in);
printBox(); // Call the printBox
method.
printArrow(scan.nextInt()); // Call
the printArrow method.
printArrow(scan.nextInt()); // Call
the printArrow method.
}
}
Output :