Search the Whole World Here.,.,

Program to Print Triangle Pattern in java


Step 1. Open the Notepad.













Step 2. Now just Copy and Paste the code in Notepad.


import java.io.*;
class triangle {
    public static void main ( String yaarnotechnology[] ){
        InputStreamReader istream = new InputStreamReader(System.in) ;
        BufferedReader read = new BufferedReader(istream) ;
        System.out.print("Enter Triangle Size : ");
        int num=0;
        try{
            num=Integer.parseInt( read.readLine() );
        } catch(Exception Number){
            System.out.println("Invalid Number!");
        }
            for(int i=1;i<=num;i++){
                for(int j=1; j < num- (i-1); j++){
                    System.out.print(" ");
                }
                for(int k=1; k<=i; k++){
                    System.out.print("*");
                    for(int k1=1; k1 < k; k1 += k){
                        System.out.print("*");
                    }
                }
                System.out.println();
            }
    }
}


Step 3. Save the file as name.java



Step 4. Now open Command Prompt.

















Step 5. Type cd desktop and Press Enter.


















Step 6. Now type javac name.java and Press Enter.


















Step 7. At last type java triangle and then Press Enter.


















Step 8. Enter Triangle Size of your choice


Output:










EmoticonEmoticon