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();
        }
      }
}









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
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'
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
TRIANGLE OF *S AT THE BOTTOM RIGHT!!! - Java Beginners
TRIANGLE OF *S AT THE BOTTOM RIGHT!!!  My Question is to : "Write a program that inputs one integer m and outputs an m-line high triangle of *'s with the right angle at the bottom-right." PROBLEM: Have tried so many times
Printing stars
these strings in java so that i can put it in array..can somebody help
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
drawing triange using stars - Java Beginners
drawing triange using stars  How do i Write a program to draw the boundaries of a plot of land with the structure shown in the diagram, for any set...*;public class Triangle{ public static void main(String args[]){ Polygon tri = new
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-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 '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 '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 '
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
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
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
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
Draw a Triangle using a Line2D
draw three line segments using the class Line2D to create a triangle. ADS... Draw a Triangle using a Line2D       This section illustrates you how to draw a triangle using
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
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
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 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
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
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... of Prime Number program in Java: package Tutorial; public class PrimeNumber
Write a program to calculate factorial of any given number
program to calculate factorial of any given number. First of all define a class... given number      ... in the range of double data type in java. Here is the code of program:ADS
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
How can i draw a line using java swings
How can i draw a line using java swings  Sir my program contains different components i am using JFrame. I want to draw a straight line between components(Jtextfeilds, Jlabels).So could you help me for it. Thank You
How can i draw a line using java swings
How can i draw a line using java swings  Sir my program contains different components i am using JFrame. I want to draw a straight line between components(Jtextfeilds, Jlabels).So could you help me for it. Thank You
Magic number Java Program
Magic number Java Program  write a program that guesses what number the user is thinking of. Below is a sample transcript: Think of a number between... cannot just cut-n-paste these numbers into your program). You can
Draw Line in J2me
Draw Line in J2me       In this example we are going to show you how to draw a line using J2ME. Please... and class to draw a line.  Basically in J2ME, Canvas class is used to draw
Write a program to find a factorial in any given number
Write a program to find a factorial in any given number This programming tutorial will teach you how to write a factorial of any given number... number less than or equal to n. For example  4! = 4 * 3 *2 * 1
Java Automorphic number program - Java Beginners
Java Automorphic number program  Write a program to read a positive...){ if ((n*n) % d == n){ System.out.println("Automorphic Number... void main(String args[]){ System.out.print("Enter any number
Java programming help - Java Beginners
Java programming help  Write a program that asks the user for an integer, and if the input is positive, puts stars on the screen - one star on line one, two stars on line two, three stars on line three, and so on until
Dynamic Line draw in JSp
Dynamic Line draw in JSp  In my application. I have one source selected from listbox and multiple targets selected from checkboxes. After submitting... multiple target. And each line should have dynamically link of other jsp page
Prime number program in java
Prime number program in java In this example you will learn how to write a program to generate and check  prime number  in java. As we know prime number are those number which are divisible by 1 or itself, first define
J2ME Draw Triangle
J2ME Draw Triangle      ... application, we are using canvas class to draw the triangle on the screen. In this example you will learn how to draw a triangle and filling it with particular color
how to write a program in java to print numbers in equalateral triangle
how to write a program in java to print numbers in equalateral triangle ... static void main(String args[]){ int n=1; for(int i=1;i<=5;i=i+2){ for(int j=1;j<=i;j++){ System.out.print(n
Write a program in Java to convert Decimal number into Binary number
Write a program in Java to convert Decimal number into Binary number  Hi, I have decimal number and I want to convert it to Binary. How to Write a program in Java to convert Decimal number into Binary number? Thanks
How to Read file line by line in Java program
by line in Java. But there are various ways that can help read a larger file... having less amount of memory. In the example of Java Read line by line below... of read file line by line in Java is printed on console.ADS_TO_REPLACE_5
C Program to Print Pascal Triangle - Development process
C Program to Print Pascal Triangle  I want C Program to Print Pascal Triangle.  Hi Friend, Try the following code: #include #include void main(){ int a[15][15],i,j,rows,num=25,k; printf("\n enter
A Program To Print A Equilateral Triangle
A Program To Print A Equilateral Triangle  Write A program to Print Following In Java : 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Please provide the java code for the given program.
Please provide the java code for the given program.   We need an application for managing an educational institute. That application should provide...: StudentAddr: StudentDob: Email: Course ALL Java C C++ Oracle Fees: Duration: Faculty

Ads