• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help

 
pras
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perhaps you are in the wrong forum...here you should be discussing problems related to SCJP preperations !!
 
pras
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please guys help.

i want it
 
Abdullah Mamun
Ranch Hand
Posts: 99
Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi can anyone tell me the condition to check for prime numbers.

the numbers are entered from command line
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic