This is Half Pyramid image, but in programming: this code is not fixed name, it's used to just define this code.
Half Pyramid Pattern Java Code:
public class HalfPyramid {
public static void main(String[] args) {
int n = 11;
for (int i = 1; i <= n; i++) {
// number print
for (int num = 1; num <= i; num++) {
System.out.print(num);
}
System.out.println();
}
}
}
Output:
java .\HalfPyramid.java
1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910
1234567891011
No comments:
Post a Comment