NDROID TECH
  • Home (current)
  • Blog
  • About
  • Categories
    Entertainment
    Technology
    Programming
    Android
    Web Development
    Games
    Ethical Hacking
    motivational
  • Contact
  • Privacy Policy
  • Terms of Use
  1. Home
  2. Blog
image not available
  • 2020-03-24
  • admin
  • NPTEL,SWAYAM,JAVA,Programming
  • 182

NPTEL WEEK 8 Q 3 : JAVA Programming Solution 2020



Share :

Java Week 8: Q3

Due on 2020-03-26, 23:59 IST
Write a program which will print a pyramid of "numbers" 's of height "n" and print the sum of all number's in the pyramid.

For example:

input: 5

output: 
        1 
      1 2 3 
    1 2 3 4 5 
  1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 9 
95

Note: Spaces must be exactly same as in the example for correct evaluation. 
Select the Language for this assignment.
File name for this program :

import java.util.*;

  public class Pattern3 {

    public static void main(String[] args) {

        Scanner inr = new Scanner(System.in);

       int n = inr.nextInt();

        // Add the necessary code in the below space

      int k = 1,sum=0;

        for(int i = 1; i <= n; ++i, k = 1) {

            for(int space = 1; space <= n-i; ++space) {

                System.out.print("  ");

            }

            while(k <= 2 * i - 1) {

                System.out.print(k+" ");

                sum=sum+k;

                ++k;

            }

            System.out.println();

        }

         System.out.println(sum); 

    }

}   
​


Categories

  • Entertainment 3
  • Technology 14
  • Programming 9
  • Android 11
  • Web Development 5
  • Games 14
  • Ethical Hacking 3
  • motivational 2


Stay Connected

  • Twitter
  • Facebook
  • Dribble
  • Pinterest


Editor's Choice

fantastic cms
Now ट्रैक कर सकेंगे कोरोना वायरस की जानकारी !!!
2020-03-22
fantastic cms
Whatsapp यह है खास फीचर| यूजर्स मैसेज की कर पाएंगे जांच !!!!!
2020-03-23


fantastic cms
सोशल मीडिया प्लेटफॉर्म से इन्हें हटाने के निर्देश : IT मंत्रालय सख्त
2018-04-27
fantastic cms
Benefits of WhatsApp ????
2018-04-27


fantastic cms
The future of वेब डिजाइनिंग on earth
2018-04-27
fantastic cms
Computer Science Projects and ideas for Engineering students as well as interested students.
2018-04-27


NDROID TECH

This is a ndroid.tech is related to technology blog. since active from 2018

About Us

Popular Posts

fantastic cms
How Corona effected on technology ???
2020-03-21
fantastic cms
How to activate windows 10 using CMD or batch file
2020-06-01

Signup to our newsletter

We respect your privacy.No spam ever!

  • Facebook
  • Twitter
  • Google+
  • Pinterest

ndroid tech 2021 | Brought To You by ndroid.tech