Print Triangle in java programming # Program 1

in #java7 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");
}
}
}

Coin Marketplace

STEEM 0.26
TRX 0.20
JST 0.038
BTC 96240.27
ETH 3591.45
USDT 1.00
SBD 3.91