permaculture playing cards*
The moose likes Beginning Java and the fly likes Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help" Watch "Help" New topic
Author

Help

pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
import java.io.*;

public class Pyramid1
{
void printPyramid ( int num, int[] dataOfNum ) {
int line = 1;
while ( 0 < ( num-- ) ) {
for( int i = 1; i <= num + 5 ; i++ ) {
System.out.print ( " " );
}
for( int j = 1; j <= line; j++ ) {
System.out.print ( dataOfNum[j - 1] );
System.out.print ( " " );
}
System.out.println ( "" );
line++;
}
}

public static void main ( String args[] ) {

Integer iv=new Integer(args[0]);
int num=iv.intValue();

//int nLength = 10;
int[] arrayOfNumbers = new int [ num ];

Pyramid1 objPr = new Pyramid1 ();
for ( int nLoop = 0; nLoop < num; nLoop++ ) {
arrayOfNumbers [ nLoop ] = nLoop + 2;
}
objPr.printPyramid ( num, arrayOfNumbers );
}
}

i get the output
1
1 2
and so on


i want output of form

1 3 1
1 3 5 3 1
1 3 5 7 5 3 1
�����.
so please help
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
perhaps you are in the wrong forum...here you should be discussing problems related to SCJP preperations !!


"History would be kind to me, for I intend to write it."
pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
please guys help.

i want it
Abdullah Mamun
Ranch Hand

Joined: Mar 19, 2007
Posts: 99

Hi prasanna

The source you have written contains wrong logic in several places...
Here is a very simple naive source which will give the output you want. But you have to correct the spacing for numbers>10...



Hope this will help.


MooN
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Thank you for helping, but Prasanna Sheregar would have learned a lot more if you had only pointed out the origin of the errors. It is better to work thing sout for oneself than be given an answer.
pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
hi can anyone tell me the condition to check for prime numbers.

the numbers are entered from command line
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42367
    
  64
Let's not talk about prime numbers in this thread, since you have posted the same question in this thread. We try to keep each thread to a single topic.


Ping & DNS - my free Android networking tools app
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help