Home Answers Viewqa Java-Beginners Java program to draw a triangle of stars given N the number of stars at the bottom line

 
 


Fatima Sadiq
Java program to draw a triangle of stars given N the number of stars at the bottom line
1 Answer(s)      a year ago
Posted in : Java Beginners

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 Pages:
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
stars question
stars question  program to get this output
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
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
Printing stars
these strings in java so that i can put it in array..can somebody help
triangle
triangle  how to draw triangle numbers with stars in html with the help of javascript
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
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
triangle  Write a program that makes use of a class called... the sides of a triangle If they can form a triangle, determine and print if they can also form the sides of a right-angle triangle The class should include proper data
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
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 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
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
Line Number Reader Example
Line Number Reader Example      ... class is provide getLineNumber() method to get the number of line. We...(): This method is used to get the number of line. readLine(): This method
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
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 Line in PowerPoint Presentation Using Java
Draw Line in PowerPoint Presentation Using Java  ... is used to add the color of the line.    The code of the program is given...;}} The output of the program is given below: Download this example
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
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
Write a program to construct a triangle with the ?*?
Write a program to construct a triangle... '*'. First of all make a class named 'triangle' under the Java I/O package... any number on your command window and surely you will get a triangle shape
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
finding the eigenvalues and eigenvector of n*n matrix in java
finding the eigenvalues and eigenvector of n*n matrix in java  Here... icmax = 10; // the maximum iterations number int[] colRowOfElMax = new int[size... the diagonal elements of A and puts them into B * * @param A * @param n
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program
pascal triangle
pascal triangle   given string : char str[]="123456789"; write a program in 'c'-language that displays the following: 1 232... the following link: C Pascal's Triangle Thanks
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
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 java. Here is the code of program: import 
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
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
Draw a diamond - Java Beginners
Draw a diamond  I want to draw a diamond shapein java using (*) in 9... the number of star lines and number of blanks"); noOfstarlines=console.nextInt... printStars(int size,int c) { int i,j,k,l,m,n; for(i=1;i<=size;i
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
How to calculate area of triangle
of triangle. Description of this program  This is very java programming tutorial program in the section you see that how to get triangle values. First... of triangle. Then the program perform and  return of triangle value
PHP GD draw line
($handle, 255, 255, 255); $line_color = ImageColorAllocate ($handle, 0, 0, 0); ImageLine($handle, 65, 0, 130, 50, $line_color); ImageJpeg ($handle); ?> After running the program you will get the following output
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
triangle shape
triangle shape  Hi, I have to create a program which its output is: + ++ +++ ++++ and this what I did so far : package symbols; import...: + ++ +++ ++++ ++++ I don't know why it keep giving me the last line twice !! what
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
Command line argument in java
Command line argument in java. In this section we are going to discuss about command line argument in java. Command line argument allow a user to pass... user to pass any number of  argument to the command line. When running
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
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
java line chart
java line chart  Hi, I want to draw a graphic in java line chart and ? searched the documents ?n the web. I found the example codes ?n your site (http://www.roseindia.net/chartgraphs/xyline-chart.shtml) and tr?ed ?n my
program - Java Beginners
program  1-Write a computer program using java to generate following... static void main(String args[]) 2-Write a computer program using java.... Please try the following codes : // Program 2 import java.io.*; class
How to Check Automorphic Number using Java Program
How to Check Automorphic Number using Java Program Automorphic numbers are the numbers whose square ends with the number itself or you can say it is a number whose square ends with the given integer. For example,5 is an automorphic number
extracting phone number n storing in excel
extracting phone number n storing in excel  i need a program to open a doc file n extract phone numbers from it and store it in a excel sheet?? plz do reply and help me out with the problem
extracting phone number n storing in excel
extracting phone number n storing in excel  i need a program to open a doc file n extract phone numbers from it and store it in a excel sheet?? plz do reply and help me out with the problem
Command Line Arguments in Java Program
Command Line Arguments in Java Program       Java application can accept any number of arguments... invoking the application. When running the java program from java command
Prime Number in Java
Prime Number in Java       This Java programming tutorial, we will be read how to get prime number between 1 to given number. First of all we have to define a class "
Java Program
First line contains one integer N indicating the number of clue words which follow... and the number of cows and bulls for each word, your program should be able to work out...Java Program  Problem Statement You are required to play a word-game

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.