for loop

Java program to Integrated triangle patterns using for loop

Java program to Integrated triangle pattern using for loop

In this tutorial, we will discuss a concept of  Java program to Integrated triangle patterns using for loop in Java language

In Java  programming language, we can use for loop ,while loop and do-while loop to display different number (binary, decimal), alphabets or star patterns programs.

In this article, we are going to learn  how to Display Integrated triangle star and number patterns  using for loop in Java language

Java code to Integrated triangle star patterns

Double Triangle star pattern 1

Program 1

import java.util.Scanner;
class integratedTrianglefor{
public static void main(String args[]){
    int i,j,k;  //variable declaration
    Scanner scan=new Scanner(System.in);
//create a scanner object for input

//get input from the user for rows
System.out.print("Enter the number of rows: ");
int rows=scan.nextInt();

for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  System.out.print("*"); //print star
  
}
for(j=i*2; j<rows*2; j++){
  System.out.print(" ");  //print space
  
}

for(k=i; k>=1; k--){
  System.out.print("*");  //print star
  
}

  System.out.print("\n");

}
}
}

When the above code is executed, it produces the following results

Integrated triangle pattern

 

Double Triangle star pattern 2

Program 2

import java.util.Scanner;
class integratedTrianglefor1{
public static void main(String args[]){
    int i,j,k;  //variable declaration
    Scanner scan=new Scanner(System.in);
//create a scanner object for input

//get input from the user for rows
System.out.print("Enter the number of rows: ");
int rows=scan.nextInt();

for(i=rows; i>=1; i--){
  for(j=rows; j>=1+rows-i; j--){
  System.out.print("*");
  
}
for(j=i*2; j<rows*2-1; j++){
  System.out.print(" ");
  
}

for(k=1+rows-i; k<=rows; k++){
    if(k!=1)
  System.out.print("*");
  
}

  System.out.print("\n");

}
}
}

When the above code is executed, it produces the following results

Integrated triangle pattern

Java code to Integrated triangle number patterns

Double Triangle number pattern 1

Program 1

import java.util.Scanner;
class integratedTrianglefor{
public static void main(String args[]){
    int i,j,k;  //variable declaration
    Scanner scan=new Scanner(System.in);
//create a scanner object for input

//get input from the user for rows
System.out.print("Enter the number of rows: ");
int rows=scan.nextInt();

for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  System.out.print(j);
  
}
for(j=i*2; j<rows*2; j++){
  System.out.print(" ");
  
}

for(k=i; k>=1; k--){
  System.out.print(k);
  
}

  System.out.print("\n");

}
}
}

When the above code is executed, it produces the following results

Integrated triangle patterns

 

Double Triangle number pattern 2

Program 2

import java.util.Scanner;
class integratedTrianglefor1{
public static void main(String args[]){
    int i,j,k;  //variable declaration
    Scanner scan=new Scanner(System.in);
//create a scanner object for input

//get input from the user for rows
System.out.print("Enter the number of rows: ");
int rows=scan.nextInt();

for(i=rows; i>=1; i--){
  for(j=rows; j>=1+rows-i; j--){
  System.out.print(j);
  
}
for(j=i*2; j<rows*2-1; j++){
  System.out.print(" ");
  
}

for(k=1+rows-i; k<=rows; k++){
    if(k!=1)
  System.out.print(k);
  
}

  System.out.print("\n");

}
}
}

When the above code is executed, it produces the following results

Integrated triangle patterns

 

Double Triangle number pattern 3

Program 3

 

import java.util.Scanner;
class IntegratedTriangle5{
public static void main(String args[]){
    int i,j,k;  //variable declaration
    Scanner scan=new Scanner(System.in);
//create a scanner object for input

//get input from the user for rows
System.out.print("Enter the number of rows: ");
int rows=scan.nextInt();
for(i=rows; i>=1; i--){

     for(j=1; j<=i; j++){
         System.out.print(j);
             }

     for(j=i*2; j<rows*2-1; j++){
         System.out.print(" ");
            }

     for(k=i; k>=1; k--){
        if(k!=rows)
         System.out.print(k);
              }
System.out.print("\n");

         }
    }
}

When the above code is executed, it produces the following results

Integrated triangle pattern

 

Similar post

C program to Integrated triangle patterns using for loop

C++ program to Integrated triangle patterns using for loop

 

Suggested for you

Java language data types and variables

For loop in Java language

Nested for loop in Java language

 

Display integrated pyramid star pattern in Java using while loop
C++ program to Integrated triangle patterns using for loop
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…

2 months 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