-
April 11th, 2010, 08:33 AM
#1
Starter Java programmer
i wanted this as my program output.
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
n go on n on.
Till now i have programmed this much but not gettin the correct output...!!
import java.util.*;
class pyramid
{
public static void main(String args[])
{
int i,k,j,r;
System.out.print("Enter No. of Rows : ");
Scanner a=new Scanner(System.in);
r=a.nextInt();
for(i=1;i<=r;i++)
{
for(j=1;j<=i;j++)
System.out.print(" "+j);
for(k=i-1;k>=1;k--)
System.out.print(" "+k);
System.out.println(" ");
}
}
}
/* OUTPUT
D:\Salil JAVA>javac pyramid.java
D:\Salil JAVA>java pyramid
Enter No. of Rows : 4
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
D:\Salil JAVA>
*/
I have coded most of it..
Just missin the spaces...!!
and can anyone help me out with
+*
++**
+++***
++++****
+++++*****
thnx waiting eagerly for ur replies...!!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|