0-1 Traingle Pattern
import java.util.*;
// import java.util.Scanner;
public class practice {
public static void invertedhalfpryaminnumberpattern(int n){
int k=0;
for(int row=1;row<=n;row++){
for(int col=1;col<=row;col++){
if(col%2==0){
System.out.print(0+" ");
}
else{
System.out.print(1+" ");
}
}
System.out.print("\n");
}
}
public static void main(String[] args) {
Scanner s =new Scanner(System.in);
int n;
System.out.println("Enter the size of square matrix");
n=s.nextInt();
invertedhalfpryaminnumberpattern(n);
}
}
Output:-
Comments
Post a Comment