Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1
1 2
1 2 3
1 2 3 4
class Pyramid1
{
public static void main(String args[])
{
int i,j;
for(i=1;i< =4;i++)
{
for(j=1;j< =i;j++)
System.out.print(" "+j);
System.out.print("\n");
}
}
}
/********* OUTPUT ********
1
1 2
1 2 3
1 2 3 4 */
Labels: Core Java, Pyramid
This Post has 31 Comments Add your own!
ket - February 18, 2009 8:28 PM
I want the answer of:
1
12
123
12
1
Lionel - February 18, 2009 9:03 PM
here is the code :
class Pyramid1
{
public static void main(String args[])
{
int i,j;
for(i=1;i< =3;i++)
{
for(j=1;j< =i;j++)
System.out.print(" "+j);
System.out.print("\n");
}
for(i=2;i> =1;i--)
{
for(j=1;j< =i;j++)
System.out.print(" "+j);
System.out.print("\n");
}
}
}
90
890
7890
67890
567890
4567890
34567890
234567890
1234567890
vikas - December 27, 2009 8:34 PM
i want answer of:
*
* *
* * *
* * * *
Anonymous - February 3, 2010 8:15 AM
hi i need
1
2 3 2
3 4 5 4 3
4 5 6 7 6
5 6 7 8 9
Anonymous
5 4
8 7 6 5
- March 28, 2010 9:47 PM
hi
i want this output
4
3 4 3
2 3 4 3 2
1 2 3 4 3 2 1
Anonymous - March 28, 2010 9:49 PM
hi
i want this output
4
3 4 3
2 3 4 3 2
1 2 3 4 3 2 1
Anonymous - March 28, 2010 9:49 PM
hi
i want this output
4
3 4 3
2 3 4 3 2
1 2 3 4 3 2 1
Anonymous - May 12, 2010 7:00 PM
write a program to print the following structure
1 2 3 4 5
2 3 4
3
2 3 4
1 2 3 4 5
Anonymous - June 23, 2010 5:55 PM
class Loop
{
public static void main (String args[])
{
for
(int i=1; i<=9; i++)
{
for
(int j=1; j<=i; j++)
{
System.out.print("");
System.out.print(*);
}
System.out.print("\n");
}
System.out.println ("\n");
}
}
Anonymous - July 8, 2010 9:19 PM
i want a program to print
1
2 3
4 5 6
7 8 9 10
Anonymous - August 9, 2010 4:30 PM
Write a java program to print
123
456
789
Anonymous - August 9, 2010 4:32 PM
Write a java program to print
123
456
789
Anonymous - August 24, 2010 3:25 PM
hw if using the 'do while' loop?
Anonymous - September 9, 2010 5:39 PM
I want answer to this pls...
1
222
33333
4444444
555555555
Anonymous - October 13, 2010 8:52 PM
@abey:
class Pyramid{
public static void main(String args[]){
int i,k,j;
for(i=1;i<=128;i= i*2){
for(j=1; j<=i; j=j*2)
System.out.print(j + " ");
int s, p;
s = 1;
p = 1;
for (int i = 1; i <= n; i++) {
p = 1;
System.out.print(p);
while (s <= i) {
System.out.print(p *= 2);
s++;
}
while (s > 1) {
System.out.print(p /= 2);
--s;
}
System.out.println();
}
}
//expected output for this one is as follows:
1
121
12421
1248421
etc. etc.
Anonymous - November 3, 2010 3:53 PM
hi..
Can anyone give me code for below output...??
A
A B A
A B C B A
A B C D C B A
A B C D E D C B A
Anonymous - November 28, 2010 1:07 PM
i need a code for this program :]
kindly help me thanks .
1
232
34543
4567654
567898765
tuxedo mask - December 15, 2010 7:13 AM
how to create triangle of numbers in this type of form:
output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Tripta - March 9, 2011 1:34 PM
*
* *
* * * *
* * * * * * * *
Tripta - March 9, 2011 1:35 PM
1
22
333
4444
55555
6666
777
88
9
Anonymous - May 4, 2011 12:22 PM
i need code for this
1
22
333
4444
55555
6666
777
88
9
Anonymous - June 8, 2011 1:53 AM
hey
1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9
tom code fr
3
4 4
5 5 5
6 6
7
class Pyramid1
{
public static void main(String args[])
{
int k;
//for loop for the no of lines to print till 55555
for(int i=1;i<=5;i++)
{
System.out.println();
//for loop for printin da nos
for(int j=1;j<=i;j++)
{
k=i;
System.out.print(k);
}
}
//making k=6 to start printin 6666 after 55555
k=6;
for(int i=1;i<=4;i++)
{
//to change the line
System.out.println();
for(int j=4;j>=i;j--)
{
System.out.print(k);
}
k++;
}
}
}
hope it helps u,i hav tried it nd it works.