Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


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 and 11 months 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...


Advertisement
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:
stars question
stars question  program to get this output
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
Advertisements
Printing stars
these strings in java so that i can put it in array..can somebody help
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
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 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
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  how to draw triangle numbers with stars in html with the help of javascript
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
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
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
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
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
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
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
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
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 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
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
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 
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
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...()?. The output of read file line by line in Java is printed on console
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
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
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
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
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
Java Generic program with command line argument
Java Generic program with command line argument  Implement Generic to perform arithmetic evaluation using command line argument by using Java
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
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
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
Recursion - Java Beginners
); System.out.println("Triangle=" + theAnswer); } public static int triangle(int n) { if (n == 1) return 1; else return (n + triangle(n - 1... stars ) { for ( int i=0; i  http://www.roseindia.net/java/example
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c  class rose { int n...("Enter the number"+n); System.out.println("\nReverse the number"+i); } Public
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
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
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
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
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
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
Compiling and Running Java program from command line
Compiling and Running Java program from command line - Video tutorial that explains you all steps necessary to compile and run the Java program from dos... of compiling and running java program from command line. We have also video
line number in a file of entered string
line number in a file of entered string  when i entered string from console , it should show line number in a file of that string
write a java program for inserting a substring in to the given main string from a given position
write a java program for inserting a substring in to the given main string from a given position  write a java program for inserting a substring in to the given main string from a given position
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
Advertisements
 

 

 

DMCA.com