Pattern Programs in Java
Pattern 1
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
import java.util.Scanner;
public class Pattern1 {
public void Display(int rows) {
for(int i=1;i<=rows;i++) {
for(int j=1;j<=i;j++) {
System.out.print(j);
}
System.out.println();
}
}
public static void main(String[] args) {
// Initialize the Scanner
Scanner sc= new Scanner(System.in);
//Reading the no of rows
System.out.println("Enter the no of rows");
int rows = sc.nextInt();
Pattern1 obj=new Pattern1();
obj.Display(rows);
sc.close();
}
}
No comments:
Post a Comment