How to do Right Triangle pattern in java

Right Triangle pattern


Steps to do this :-
1. take 3 integer n,i,j n is for user input i and j is for loop
2. start for loop for(i=1;i<=n;i++) and inside of this loop write for(j=1;j<=i;j++) inside the j block print("*") and outside of j block print new line.
3.save and run
The Source code
import java.util.Scanner;
class pat
{
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int i,j,n;//i j is for loop and n is for input
        System.out.println("enter the number");
        n=s.nextInt();
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=i;j++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

 OUTPUT





WATCH MY VIDEO 

Comments

Popular Posts