# Java Program to Print Inverted Right-Angled Triangle with Same Binary Number in Alternate Rows Pattern

## Print Inverted Right-Angled Triangle with Same Binary Number in Alternate Rows Pattern

In the previous article, we have discussed Java Program to Print Left Angled Triangle Number Pattern

In this article we will see how to print inverted right angled triangle with same binary number in alternate rows pattern.

Example-1

When size value=5

1 1 1 1 1
0 0 0 0
1 1 1
0 0
1
Example-2:

When size value=4

0 0 0 0
1 1 1
0 0
1

Now, let’s see the actual program to print it.

Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners tutorial.

Approach:

• Enter total size and number store them in integer variables size.
• Take one outer for loop to iterate the rows.
• Take inner for loop to print value by calculating the reminder.

### Java Code to Print Inverted Right-Angled Triangle with Same Binary Number in Alternate Rows Pattern

import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
// taking size of no. of iteration
//Row and column are the iterators
int size , numberOfRows , numberOfColumns;
// Create a new Scanner object
Scanner scanner = new Scanner(System.in);
// Get the number of rows from the user
System.out.println("Enter the number of rows : ");
size = scanner.nextInt();
//Outer loop to iterate the rows
//Iterates from size to 1
for ( numberOfRows = size; numberOfRows >=1 ; numberOfRows--)
{
//Inner loop to iterate the columns
//Iterates from  1 to row value
for (  numberOfColumns = 1; numberOfColumns <= numberOfRows ; numberOfColumns++)
System.out.print(numberOfRows%2);
// printing in new line
System.out.println();
}
}
}

Output :

Enter the number of rows : 5

1 1 1 1 1
0 0 0 0
1 1 1
0 0
1

### C Code to Print Inverted Right-Angled Triangle with Same Binary Number in Alternate Rows Pattern

#include <stdio.h>
#include <stdlib.h>
int main()
{
int size , numberOfRows , numberOfColumns;
printf("Enter the number of rows : ");
scanf ("%d",&size);
for ( numberOfRows = size; numberOfRows >=1 ; numberOfRows--)
{
for (  numberOfColumns = 1; numberOfColumns <= numberOfRows ; numberOfColumns++)
printf("%d ",numberOfRows%2);
printf("\n");
}
return 0;
}

Output :

Enter the number of rows : 5

1 1 1 1 1
0 0 0 0
1 1 1
0 0
1

### C++ Code to Print Inverted Right-Angled Triangle with Same Binary Number in Alternate Rows Pattern

#include <bits/stdc++.h>
using namespace std;
int main()
{

int size , numberOfRows , numberOfColumns;
printf("Enter the number of rows : ");
scanf ("%d",&size);
for ( numberOfRows = size; numberOfRows >=1 ; numberOfRows--)
{
for (  numberOfColumns = 1; numberOfColumns <=numberOfRows ; numberOfColumns++)
cout << numberOfRows%2;

cout << "\n";
}
return 0;
}

Output :

Enter the number of rows : 5

1 1 1 1 1
0 0 0 0
1 1 1
0 0
1

Are you seeking professional help for coding in the Java programming language? The tutorial of Java Programming Examples for beginners and experts will strongly improve your coding skills then you can program for any logic in Java.

Related Java Number Pattern Programs: