Computer Science, asked by aisabhi2364, 10 months ago

Write a program in java to display all the triangular number from 3 to n , taking the value of n as a input

Answers

Answered by pavithranatarajan855
1

Answer:

import java.util.Scanner;  

public class TriangularNumbers {

 

   public static void main(String[] args) {

      int n;

      Scanner s=new Scanner(System.in);

      n=s.nextInt();

       int starting_number = 3;

       int ending_number = n;

 

       System.out.println("List of Triangular Numbers ");

       for (int i = starting_number; i <= ending_number; i++) {

           int triangular = 0;

 

 

           for (int j = 1; j <= i; j++) {

               triangular = triangular + j;

           }

           System.out.println(i + " = " + triangular);

       }

   }

}

Explanation:

I this is helpful for you.

Similar questions