Number Triangle Pattern Java Program.





package demo;
import java.util.Scanner;
public class NumberTriangle
{
 public static void main(String[] args) 
 {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print(“Enter maximum number : “);
  num = sc.nextInt();
  for (int r = 1, m = 0; r <= num + 1; r++, m++) 
  {
   for (int c = 1, n = m; c <= r; c++, n–) 
   {
    System.out.print(n);
   }
   for (int c = 1; c < r; c++) 
   {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}


Output:


run:
Enter maximum number : 5


0
101
21012
3210123
432101234
54321012345



BUILD SUCCESSFUL (total time: 3 seconds)







 



 

Number Triangle Pattern Java Program.





package demo;
import java.util.Scanner;
public class NumberTriangle
{
 public static void main(String[] args) 
 {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print(“Enter maximum number : “);
  num = sc.nextInt();
  for (int r = 1, m = 0; r <= num + 1; r++, m++) 
  {
   for (int c = 1, n = m; c <= r; c++, n–) 
   {
    System.out.print(n);
   }
   for (int c = 1; c < r; c++) 
   {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}


Output:


run:
Enter maximum number : 5


0
101
21012
3210123
432101234
54321012345



BUILD SUCCESSFUL (total time: 3 seconds)

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here