|
| ||||||||||
| Tags: java, java language, java programming, pyramid, while loop |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How to write java program to print pyramid of stars?
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. |
|
#2
| ||||
| ||||
| 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();
}
}} |
|
#3
| ||||
| ||||
| 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
}
}}
__________________ Grand Theft Auto 4 PC Video Game |
|
#4
| ||||
| ||||
| 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 |
|
#5
| ||||
| ||||
| 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();
}
}
} |
|
#6
| ||||
| ||||
| 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();
}
}
} |
|
#7
| |||
| |||
| pyraRe: How to write java program to print x shape of stars?
how to write java program to print x shape of stars? |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 string data to file using java program? | Linoo | Software Development | 5 | 21-01-2010 08:26 PM |
| how to write program on palindrome in java? | Linoo | Software Development | 3 | 26-11-2009 04:19 PM |