• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Help

 
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
 
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
 
Ranch Hand
Posts: 99
Mac Eclipse IDE
  • 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.
 
Marshal
Posts: 65464
249
  • 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
 
Rancher
Posts: 43011
76
  • 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.
 
His brain is the size of a cherry pit! About the size of this ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!