Need Additional Code

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Golam Kausher Golam Kausher is offline Offline Oct 31st, 2009, 9:39 am |
0
The program will give the following output

55 45 36

28 21

15

10 6

3 1 0


Now, I have managed to print only the followings:

55 45 36

28 21 // This line with some kind of error though it ran.



Now what should be the addtional codes to get the afformentioned
diagram?



public class Task2 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

int a = 55,

differenttiator=10;

int [][] newArray=new int[5][];

newArray[0]=new int[3];
newArray[1]=new int[2];
newArray[2]=new int[1];
newArray[3]=new int[2];
newArray[4]=new int[3];


for(int row=0; row<5; row++){
for(int col=0; col<3; col++){
newArray[row][col]=a;
System.out.print(" " +newArray[row][col]);
a=a-differenttiator;
differenttiator=differenttiator-1;
}
System.out.println("");
}



}
}
Quick reply to this message  
Java Syntax
  1.  
0
Golam Kausher Golam Kausher is offline Offline | Oct 31st, 2009
Asking Output is like

55 45 36
28 21
15
10 6
3 1 0
 
0
javaAddict javaAddict is offline Offline | Oct 31st, 2009
Don't loop like this:
  1. for(int row=0; row<5; row++){
  2. for(int col=0; col<3; col++){

Always like this:
  1. for(int row=0; row<array.length; row++){
  2. for(int col=0; col<array[row].length; col++){
 
 

Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC