Java program to draw a triangle of stars given N the number of stars at the bottom line

Java program to draw a triangle of stars given N the number of stars at the bottom line

Write a program to draw a triangle of stars given N the number of stars at the bottom line. can assume that N will always be an odd number with a minimum value of 3.

thanks...

View Answers

May 12, 2012 at 4:27 PM

The given code accepts the number from the user. Accordingly, the pyramid of aestricks is displayed.

import java.util.*; 

public class Pattern {
      public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter N: ");
        int N=input.nextInt();

        for(int i=1;i<=N;i++)       {
        for(int j=0;j<N-i;j++)System.out.print(" ");
        for(int j=0;j<(2*i-1);j++) System.out.print("*");
        System.out.println();
        }
      }
}

Ads









Related Tutorials/Questions & Answers:
Java program question ...
Java program to draw a triangle of stars given N the number of stars at the bottom line  Write a program to draw a triangle of stars given N the number of stars at the bottom line. can assume that N will always be an odd number
stars question
stars question  program to get this output
Advertisements
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
ModuleNotFoundError: No module named 'stars'
ModuleNotFoundError: No module named 'stars'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'stars' How to remove the ModuleNotFoundError: No module named 'stars'
Java draw triangle draw method?
Java draw triangle draw method?  hi how would i construct the draw method for an triangle using the 'public void draw (graphics g ) method? im... want to use Line2D class to draw a triangle, then please go through
plz give me program to this: Given a string and a number ‘n’, find the ‘n’th distinct repeating character.
plz give me program to this: Given a string and a number ?n?, find the ?n?th distinct repeating character.    Given a string and a number ?n?, find the ?n?th distinct repeating character. For example, Input: Abracadabra, 1
triangle
triangle  how to draw triangle numbers with stars in html with the help of javascript
Printing stars
these strings in java so that i can put it in array..can somebody help
ModuleNotFoundError: No module named 'geo-stars'
ModuleNotFoundError: No module named 'geo-stars'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'geo-stars' How to remove the ModuleNotFoundError: No module named 'geo
ModuleNotFoundError: No module named 'moving-stars'
ModuleNotFoundError: No module named 'moving-stars'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'moving-stars' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'STARS-CMS'
ModuleNotFoundError: No module named 'STARS-CMS'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'STARS-CMS' How to remove the ModuleNotFoundError: No module named 'STARS
ModuleNotFoundError: No module named 'stars-rating'
ModuleNotFoundError: No module named 'stars-rating'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'stars-rating' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'stars-zs'
ModuleNotFoundError: No module named 'stars-zs'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'stars-zs' How to remove the ModuleNotFoundError: No module named 'stars-zs
ModuleNotFoundError: No module named 'django-rating-stars'
ModuleNotFoundError: No module named 'django-rating-stars'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'django-rating-stars' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'gh-stars-export'
ModuleNotFoundError: No module named 'gh-stars-export'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'gh-stars-export' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'gh-stars-export'
ModuleNotFoundError: No module named 'gh-stars-export'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'gh-stars-export' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'oh-my-stars'
ModuleNotFoundError: No module named 'oh-my-stars'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'oh-my-stars' How to remove the ModuleNotFoundError: No module named 'oh
ModuleNotFoundError: No module named 'oh-my-stars'
ModuleNotFoundError: No module named 'oh-my-stars'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'oh-my-stars' How to remove the ModuleNotFoundError: No module named 'oh
ModuleNotFoundError: No module named 'thank-you-stars'
ModuleNotFoundError: No module named 'thank-you-stars'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'thank-you-stars' How to remove the ModuleNotFoundError: No module named
Java Program Floyd's Triangle
Java Program Floyd's Triangle In this section you will read about how to write a Java program to print Floyd's triangle. This tutorial is about... for creating the Floyd's triangle in Java. Before writing a Java program
write a java program to print marklist of n students. input Register number, name and marks of three subjects.
write a java program to print marklist of "n " students. input Register number, name and marks of three subjects.  write a java program to print marklist of "n " students. input Register number, name and marks of three subjects
Draw a Triangle using a Line2D
draw three line segments using the class Line2D to create a triangle. ... Draw a Triangle using a Line2D       This section illustrates you how to draw a triangle using
Draw a line in a JPanel with button click in Java
Draw a line in a JPanel with button click in Java  Draw a line in a JPanel with button click in Java
Triangle Program
Triangle Program  i want program code for 1 2 3...;public class Triangle { public static void main(String[] args...(""); } } }   include using namespace std; main(){ int n,l; cin>>n
Triangle program
the code 4 this program in java    1 121 12321 1234321 write a program for this triangle    1 121 12321 1234321 write a program for this triangle    1 121 12321 1234321 write a program
2. Given a string and a number ‘n’, find the ‘n’th distinct repeating character.
2. Given a string and a number ?n?, find the ?n?th distinct repeating character.    Given a string and a number ?n?, find the ?n?th distinct repeating character. For example, Input: Abracadabra, 1 Abracadabra, 2 Abracadabra, 3
J2ME Draw Triangle, Rectangle, Arc, Line Round Rectangle Example
J2ME Draw Triangle, Rectangle, Arc, Line Round Rectangle Example... tutorial, we are going to describe how to draw a triangle, rectangle, arc, line... to use the canvas class to draw all the graphic or image. We can call the canvas
Prime Number program in Java
Prime Number program in Java will print the prime numbers between 1 to any given number. Prime Number is a number that is not divisible by any number other... program in Java: package Tutorial; public class PrimeNumber { public static
Draw Line
Draw Line  sir i want to draw a moving line in j2me.That line should also show arrow in moving direction. How can we do so
How to round a number to n decimal places in Java
How to round a number to n decimal places in Java  How to round a number to n decimal places in Java

Ads