Question: WAP to print the number in the below format.
star pattern for size :7
1
232
34543
4567654
34543
232
1
Answer :
"Success = (DSA + System Design) × Consistency × Problem-Solving + Mindfulness" 💡💻🚀
X X X X X X X X X X --------------------- X X X X X X X X X XJAVA Code:
public class HelloWorld {
static int count = 0;
public static void print(int i, int j) {
if (i <= 0 || j < 0 ) return;
System.out.print("X ");
print(i, j - 1);
if (j == 0) {
count++;
System.out.println();
print(i - 1, count);
}
}
public static void print2(int i, int j) {
if (i <= 0 || j < 0 ) return;
System.out.print("X ");
print2(i, j - 1);
if (j == 0) {
System.out.println();
print2(i - 1, i-2);
}
}
public static void main(String[] args) {
//System.out.println("Hello World2");
print(4, 0);
System.out.println("---------------------");
print2(4, 3);
}
}
Stair Problem ...Enter X,Y(Y is number of stair and Y length of stair) 15 4 1 _2 __3 ___4 __5 _6 7 8 _9 __10 ___11 __12 _13 14 15