0-1 ■ zero - one triangle pattern in java.

■》 code link -> click 👇👇👇👇



■》 Input->

import java.util.*;
public class onezerotriangle {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("enter the row size=");
        int n=sc.nextInt();
        for(int i=1; i<=n; i++){
            for(int j=1; j<=i; j++){
                if((i+j)%2==0)
                       System.out.print("1 ");
                else
                       System.out.print("0 ");
            }
            System.out.println();
        }
    }
}
■》Output->

enter the row size=>5

1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
------------------------------------------------------------------------

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.