Floyd's triangle

Java program to display triangle binary pattern

Java program to display triangle binary pattern

In this tutorial, we will discuss Java program to display triangle binary pattern

In this post, we will learn how to displayed  Floyd’s triangle binary pattern  using for loop or nested for loop in Java programming language

here, we displayed some binary Floyd’s triangle program with coding using nested for loop and also we get input from user using Scanner class  in Java language

C program to Floyd’s triangle binary pattern

the user can provide numbers as they wish and get the binary pattern according to their input

Triangle binary pattern 1

Program 1

import java.util.Scanner;
class Binarypattern2{
public static void main(String args[]){
int i,j,rows;
int count=1;
Scanner scan=new Scanner(System.in);
System.out.print("Enter the number of rows: ");

rows=scan.nextInt();

for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  if(i%2==1){
      System.out.print("0");
  }
  else{
      System.out.print("1");
  }
  

}
System.out.println();

}
}
}

When the above code executed, it produces the following results

Enter the number of rows: 8
0
11
000
1111
00000
111111
0000000
11111111

Triangle binary pattern 2

Program 2

import java.util.Scanner;
class Binarypattern3{
public static void main(String args[]){
int i,j,rows;
int count=1;
Scanner scan=new Scanner(System.in);
System.out.print("Enter the number of rows: ");

rows=scan.nextInt();

for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  if(i%2==1){
      System.out.print("1");
  }
  else{
      System.out.print("0");
  }
  

}
System.out.println();

}
}
}

When the above code executed, it produces the following results

Enter the number of rows: 8
1
00
111
0000
11111
00000
1111111
00000000

Triangle binary pattern 3

Program 3

import java.util.Scanner;
class Binarypattern1{
public static void main(String args[]){
int i,j,rows;
int count=1;
Scanner scan=new Scanner(System.in);
System.out.print("Enter the number of rows: ");

rows=scan.nextInt();

for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  System.out.print(count);
  
  }
  count=i%2;
  System.out.println();

}
}

}

When the above code executed, it produces the following results

Enter the number of rows: 8
1
11
000
1111
00000
111111
0000000
11111111

Triangle binary pattern 4

Program 4

import java.util.Scanner;
class Binarypattern4{
public static void main(String args[]){
int i,j,rows;
int count=1;
Scanner scan=new Scanner(System.in);
System.out.print("Enter the number of rows: ");

rows=scan.nextInt();

for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  if(j%2==1){
      System.out.print("1");
  }
  else{
      System.out.print("0");
  }
  

}
System.out.println();

}
}
}

When the above code executed, it produces the following results

Enter the number of rows: 8
1
10
101
1010
10101
101010
1010101
10101010

Triangle binary pattern 5

Program 5

import java.util.Scanner;
class Binarypattern5{
public static void main(String args[]){
int i,j,rows;
int count=1;
Scanner scan=new Scanner(System.in);
System.out.print("Enter the number of rows: ");

rows=scan.nextInt();

for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  if(j%2==1){
      System.out.print("0");
  }
  else{
      System.out.print("1");
  }
  

}
System.out.println();

}
}
}

When the above code executed, it produces the following results

Enter the number of rows: 8
0
01
010
0101
01010
010101
0101010
01010101

Triangle binary pattern 6

Program 6

import java.util.Scanner;
class Binarypattern6{
public static void main(String args[]){
int i,j,rows;
int count=1;
Scanner scan=new Scanner(System.in);
System.out.print("Enter the number of rows: ");

rows=scan.nextInt();

for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  if((i+j)%2==1){
      System.out.print("0");
  }
  else{
      System.out.print("1");
  }
  

}
System.out.println();

}
}
}

When the above code executed, it produces the following results

Enter the number of rows: 8
1
01
101
0101
10101
010101
1010101
01010101

Triangle binary pattern 7

Program 7

import java.util.Scanner;
class Binarypattern7{
public static void main(String args[]){
int i,j,rows;
Scanner scan=new Scanner(System.in);
System.out.print("Enter the number of rows: ");

rows=scan.nextInt();

for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  if((i+j)%2==1){
      System.out.print("1");
  }
  else{
      System.out.print("0");
  }
  

}
System.out.println();

}
}
}

When the above code executed, it produces the following results

Enter the number of rows: 8
0
10
010
1010
01010
101010
0101010
10101010

 

Suggested for you

Operator in Java language

Data type in Java language

If statement in Java language

for loop in java language

Nested for loop in Java language

 

Cpp program to display triangle binary pattern
Java program to display Binary pyramid pattern
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago