Print Triangle in java programming # Program 1

in java •  7 years ago 

Triangle Pattern

import  java.util.Scanner;
import  java.util.regex.Matcher;
import  java.util.regex.Pattern;
class Program1
{
public static void main(String args[])
{
try
{
int i,j,k;
String s;
Scanner sc = new Scanner(System.in);
System.out.println("Enetr the value");
s = sc.nextLine();
int n = Integer.parseInt(s);
for(i=0;i<=n;i++)
{
for(j=0;j<n-i;j++)
{
System.out.print("");
}
for(k=0;k<=i;k++)
{
System.out.print(k+" ");
}
System.out.print("\n");
}
}
catch(NumberFormatException e)
{
System.out.println("Please enter numeric value, try again");
}
}
}

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!