Example : 1
package com.tutorial4u;
package com.tutorial4u;
import java.util.Scanner;
public class NumberPattern {
public static void main(String[] args) {
System.out.print("Enter number of rows : ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for(int i=1;i<=num;i++){
for(int j =1; j<=i;j++){
System.out.print(j+"");
}
System.out.println();
}
}
}
Enter
number of rows : 6
1
12
123
1234
12345
123456
Example : 2
package com.tutorial4u;
import java.util.Scanner;
public class NumberPattern {
public static void main(String[] args) {
System.out.print("Enter number of rows : ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for(int i=1;i<=num;i++){
for(int j =i; j>=1;j--){
System.out.print(j+"");
}
System.out.println();
}
}
}
Enter
number of rows : 6
1
21
321
4321
54321
654321
Example :3
package com.tutorial4u;
import java.util.Scanner;
public class NumberPattern {
public static void main(String[] args) {
System.out.print("Enter number of rows : ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for(int i=1;i<=num;i++){
for(int j =1; j<=i;j++){
System.out.print(i+"");
}
System.out.println();
}
}
}
Enter
number of rows : 6
1
22
333
4444
55555
666666