Floyd's triangle

Hollow Triangle star Pattern using while loop in Java

Hollow Triangle star Pattern  using nested while loop in Java

In this tutorial, we will discuss the Hollow Triangle star Pattern in Java using nested while loop

In this program, we are going to learn about how to display  Hollow Tringle star pattern using nested while loop in Java programming  language

Here, we display some Hollow triangle Pattern program with coding using nested while loop and also program get input from the user using Scanner class in Java  programming language

The user can provide numbers as they wish and get the  Hollow Triangle pattern according to their input.

Floyd’s triangle star pattern 1

Program 1

import java.util.Scanner;//import the scanner class 
class Triangle_While1{ 
public static void main(String args[]){ 
Scanner scan=new Scanner(System.in);
//create a scanner object 
System.out.print("Enter the number of rows"); 
int rows=scan.nextInt();

int i,j;
    i=1;
    while(i<=rows){
        j=1;
        while(j<=i){
        System.out.print(" ");
        
    if(j==1 || j==i ||i==rows )
        System.out.print("*");
    else
        System.out.print(" ");
    j++;;
}
i++;
System.out.print("\n");//Move to the next line for print
    }
}
}

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

Hollow Triangle star Pattern

Floyd’s triangle star pattern 2

Program 2

import java.util.Scanner;//import the scanner class 
class Triangle_While2{ 
public static void main(String args[]){ 
Scanner scan=new Scanner(System.in);
//create a scanner object 
System.out.print("Enter the number of rows: "); 
int rows=scan.nextInt();

int i,j;
    i=1;
    while(i<=rows){
        j=i;
        while(j<rows){
        System.out.print(" ");
        j++;
        }
        j=1;
        while(j<=i){
        
    if(j==i || j==1 ||i==rows )
        System.out.print("*");
    else
        System.out.print(" ");
    j++;;
        }
        i++;
System.out.print("\n");//Move to the next line for print
}

}
}

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

Hollow Triangle star Pattern

 

Floyd’s triangle star pattern 3

Program 3

import java.util.Scanner;//import the scanner class 
class Triangle_While3{ 
public static void main(String args[]){ 
Scanner scan=new Scanner(System.in);
//create a scanner object 
System.out.print("Enter the number of rows: "); 
int rows=scan.nextInt();

int i,j;
    i=1;
    while(i<=rows){
        j=1;
        while(j<=rows){
        
    if(j==i || j==rows ||i==1 )
        System.out.print("*");
    else
        System.out.print(" ");
    j++;;
        }
        i++;
System.out.print("\n");//Move to the next line for print
}

}
}

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

Hollow Triangle Pattern

 

Floyd’s triangle star pattern 4

Program 4

import java.util.Scanner;//import the scanner class 
class Triangle_While4{ 
public static void main(String args[]){ 
Scanner scan=new Scanner(System.in);
//create a scanner object 
System.out.print("Enter the number of rows: "); 
int rows=scan.nextInt();

int i,j;
    i=1;
    while(i<=rows){
        j=i;
        while(j<=rows){
        
    if( i==1|| j==i || j==rows)
        System.out.print("*");
    else
        System.out.print(" ");
    j++;;
        }
        i++;
System.out.print("\n");//Move to the next line for print
}

}
}

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

Hollow Triangle Pattern

 

Suggested for you

Operator in Java language

Datatype in Java language

While loop in Java language

Nested while loop in Java language

Triangle Hollow Pattern using nested while loop in Cpp
Hollow Pyramid Pattern in Java using nested while
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

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

19 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago