Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to write java program to print pyramid of stars?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 27-11-2009
Member
 
Join Date: Nov 2009
Posts: 42
How to write java program to print pyramid of stars?
  

Hi,
I am T.Y.B.Sc.IT student. I recently started learning java language. Yesterday our sir has given us assignment in which there is a program like write java program to print pyramid of stars. I used lot of various method but I didn't get the solution. If you have any idea about it please share with me.

Reply With Quote
  #2  
Old 27-11-2009
Member
 
Join Date: May 2008
Posts: 2,283
Re: How to write java program to print pyramid of stars?

This is simple program to make pyramid.

Code:
public class pyramid
{
public static void main(String args[])
{
for(int x=1;x<10;++)
{
for(int y=o;y<x;++)
{
System.out.print("*");
}
System.out.println();
}
}}
Reply With Quote
  #3  
Old 27-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,385
Re: How to write java program to print pyramid of stars?

Code:
public class pyramid
{
public static void main(String args[])
{
int c=1;

for(int x=1;x<5;++)
{
for(int y=x;y<5;++)
{
System.out.print(" ");
}
for(int t=1;t<=c;t++)
{
if(t%2==0)
System.out.print(" ");
else
System.out.print("*");
c+=2
}
}}
Reply With Quote
  #4  
Old 27-11-2009
Member
 
Join Date: May 2008
Posts: 2,373
Re: How to write java program to print pyramid of stars?

Code:
public static final void printStars(final int height) {


final int tl = (height * 2) - 1;
final int tl_2 = tl / 2;

StringBuilder str = new StringBuilder(tl);


for (int p = 0; p < tl; ++p) {
str1.append(' ');
}


for (int i = 0; i <= tl_2; ++i) {
str1.setCharAt(tl_2 + i, '*');
str1setCharAt(tl_2 - i, '*');
System.out.println(str1);
}


}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #5  
Old 27-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,842
Re: How to write java program to print pyramid of stars?

I think this is simplest program.


Code:
package pyramid;
 
class pyramid{
  public void pyramid(){
    
  } 
  public static void main(String[] args){
    for(int p=1; p<10; p++){
      for(int q = 0; q < p; q++){  
        System.out.print("*"); 
      }
      System.out.println();    
    }
  }
}
Reply With Quote
  #6  
Old 27-11-2009
Member
 
Join Date: Jan 2008
Posts: 1,507
Re: How to write java program to print pyramid of stars?

Code:
public class PyramidStars {
public static void main(String[] args) 
{
java.util.Scanner scanner = new java.util.Scanner(System.in);
System.out.print("Enter no. you want : ");
int S = scanner.nextInt();
for (int t = 1; t <= S; t++) {
for (int s = 1; s<=t; s++) {
System.out.print("*");
}
System.out.println();
}
}
}
Reply With Quote
  #7  
Old 19-08-2011
Member
 
Join Date: Aug 2011
Posts: 1
pyraRe: How to write java program to print x shape of stars?

how to write java program to print x shape of stars?
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to write java program to print pyramid of stars?"
Thread Thread Starter Forum Replies Last Post
How to write program to generate a pascal triangle in java? Aandaleeb Software Development 7 11-09-2011 12:37 PM
how to write this pyramid using java? Rainy Software Development 1 07-09-2011 02:30 PM
Need help to write this program in java? frkadeel Software Development 1 01-12-2010 02:58 PM
How to write java program to find factorial of number? Balamohan Software Development 5 28-11-2009 09:14 PM
how to write program on palindrome in java? Linoo Software Development 3 26-11-2009 04:19 PM


All times are GMT +5.5. The time now is 02:47 AM.