Different Java Pattern Programs @ Lifebix

Java Pattern Programs:

Pattern Program I:
import java.util.Scanner;
public class pattern1 {
public static void main(String args[]){
int n=1;
System.out.println(“enter the n value : “);
Scanner k=new Scanner(System.in);
n=k.nextInt();
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
System.out.print(+i” “);
}
System.out.print(“\n”);
}
}
}

output:
enter the n value :
5
11111
22222
33333
44444
55555

Pattern Program II:
public class patterns {

public static void main(String args[]){
int n;
System.out.print(“enter the n value:”);
Scanner g=new Scanner(System.in);
n=g.nextInt();

int i,j;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){

System.out.print(” \t”+j);

}

System.out.print(“\n”);

}

Output
enter the n value:8
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8

Leave a Reply

Your email address will not be published.