JavaTech
Pages - Menu
(Move to ...)
Home
Compilation Process
Algorithms || Introduction
▼
Pages
(Move to ...)
Algorithms || Introduction
Compilation Process
▼
Tuesday, December 29, 2015
Java program to print Triangle Pattern
Triangle Pattern:
import java.io.*;
public class triangle {
public static void main (){
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();
}
}
}
The result will look like:
Thank You and Like my Facebook Page - ☺
Here
☺
and
Follow VishuRules on Twitter - @VishuRulesInc
No comments:
Post a Comment
›
Home
View web version
No comments:
Post a Comment