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
  • 181

NPTEL WEEK 8 Q 4 : JAVA Programming Solution 2020



Share :
Write a program to print symmetric Pascal's triangle of "*" 's of  height "l" of odd length . If input "l" is even then your program will print "Invalid line number".

For example:

input : 5
output:
  *
 * *
* * *
 * *
  *
input : 6

output:

Invalid line number

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 Pattern4 {

    public static void main(String[] args) {

        Scanner inr = new Scanner(System.in);

      int l = inr.nextInt();

        // Add the necessary code in the below space

​

      int ul=0; // Upper Line
    int ll=0; // Lower Line

        

    // Check whether line number is odd

    if (l%2!=0){

       ul=(l/2)+1;          

       ll=l-ul;

    //Code for upper half

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

    //Space management

    for(int s=1;s<=(ul-i); s++){

        System.out.print(" ");

    }

    // Star management

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

         System.out.print("* ");

    }

    System.out.println();

    }

            

    //Code for lower half

    int llc=ll;

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

    //Space management

    for(int s=llc;s<ll; s++){

       System.out.print(" ");

    }

    // Star management

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

       System.out.print(" *");

     }

     llc--;

    System.out.println();

        }

    }

        else{

       System.out.print("Invalid line number");

    }

​

    }

}



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