| | |
Need Additional Code
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
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("");
}
}
}
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("");
}
}
}
0
•
•
•
•
Don't loop like this:
Always like this:
Java Syntax (Toggle Plain Text)
for(int row=0; row<5; row++){ for(int col=0; col<3; col++){
Always like this:
Java Syntax (Toggle Plain Text)
for(int row=0; row<array.length; row++){ for(int col=0; col<array[row].length; col++){
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool linux list loop map method methods mobile netbeans newbie number object oracle os pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows



