package star;
import java.util.Scanner;
public class num2 {
public static void main(String[] args) {
int n, c, d,e;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows of triangle you want");
n = in.nextInt();
System.out.println("Triangle :-");
for(c=1;c<=n;c++)
{
for(d=1;d<n+1-c;d++)
{
System.out.print(" ");
}
for(e=1;e<=c;e++)
{
System.out.print(""+e);
}
System.out.print("\n");
}
}
}
import java.util.Scanner;
public class num2 {
public static void main(String[] args) {
int n, c, d,e;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows of triangle you want");
n = in.nextInt();
System.out.println("Triangle :-");
for(c=1;c<=n;c++)
{
for(d=1;d<n+1-c;d++)
{
System.out.print(" ");
}
for(e=1;e<=c;e++)
{
System.out.print(""+e);
}
System.out.print("\n");
}
}
}
Output:-
Enter the number of rows of triangle you want
4
Triangle :-
1
12
123
1234
No comments:
Post a Comment