Right-Angled Binary Triangle | Java Programs

Output:

Enter the number of rows: 5
1
10
101
1010
10101

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class BinaryTriangle {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the number of rows: ");
        int base = scanner.nextInt();
        for (int a = 1; a <= base; a++) {
            for (int c = 1; c <= a; c++) {
                if (c % 2 == 0) {
                    System.out.print("0");
                } else {
                    System.out.print("1");
                }
            }
            System.out.println();
        }
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon