The instruction for the homework are as follow:
The instruction for the homework are as follow:
"Write a program using an array that prints out the counting numbers form 1 through 60 that can be divided evenly by 4. The program should print out the numbers from left to right on your DOS screen wiht no more thatn 4 numbers on a line and at least three spaces between numbers. Also print out the number of numbers and the sum of all these numbers that can be evenly divided by 3."
The following is the code that I have so far:
/
public class ArrayTableXXX
{
public static void output()
{
/* Declare the variables used in the program. */
int x, y, num, sum, junk;
/* Initialize the variable num to one. */
num = 0;
/* This statement declares a multi-dimentional
array with 15 elements named anArray. */
int[][] anArray = new int[4][4];
/* Tells the user what the program will perform. */
System.out.println("This program outputs the counting ");
System.out.println("numbers divisible by 4 starting at 60 in ");
System.out.println("descending order using a multi-dimentional array.");
System.out.println("The output will be shown is two variations.");
System.out.println(" ");
/*This for loop assigns values the array named anArray using
four rows with four numbers in each row. */
for(x=0; x<4; x++)
{
for(y=0; y<4; y++)
{
anArray[x][y]=num * 4;
num++;
}
}
/*The following code uses two for loops
to print out the array named anarray using
four rows with four numbers in each row. */
for(x=0; x<4; x++)
{
for(y=0; y<4; y++)
{
anArray[x][y]=(num -1) * 4;
num--;
}
}
/*The following code uses two for loops
to print out the array named anarray using
four columns with four numbers in each row. */
for(x=0; x<4; x++)
{
for(y=0; y<4; y++)
{
/* This if statement is used to add two
extra space in the output of the array
value if the value.*/
if(anArray[x][y] < 100)
{
System.out.print(" " + anArray[x][y]);
System.out.print(" ");
}
else
{
System.out.print(anArray[x][y]);
System.out.print(" ");
/* This if statement prints a blank
line after all the elements in the
array have been printed. */
if (y == anArray.length)
{
System.out.println(" ");
}
}/*end of else -if statement*/
}/*end of for loop*/
System.out.println(" ");
}
System.out.println(" \n\n");
num = 1;
sum = 0;
count = 0;
/* This statement declares a multi-dimentional
array with 15 elements named anArray. */
int[][] twoArray = new int[5][4];
for(x=0; x<5; x++)
{
for(y=0; y<4; y++)
{
twoArray[x][y]=num * 3;
num++;
}
}
/*The following code uses two for loops
to print out the array named anarray using
four columns with four numbers in each row. */
for(x=0; x<5; x++)
{
for(y=0; y<4; y++)
{
/* This if statement is used to add two
extra space in the output of the array
value if the value.*/
if(twoArray[x][y] < 100)
{
System.out.print(" " + twoArray[x][y]);
System.out.print(" ");
}
else
{
System.out.print(twoArray[x][y]);
System.out.print(" ");
/* This if statement prints a blank
line after all the elements in the
array have been printed. */
if (y == twoArray.length)
{
System.out.println(" ");
}
sum = sum + twoArray[x][y];
/*count the numbers*/
count = count 1;
}/*end of else -if statement*/
}/*end of for loop*/
System.out.println(" ");
}
System.out.println(" ");
} /* end of output method */
public static void main(
String[] args)
{
ArrayTableXXX.output();
}
}/*end of ArrayTableXXX.*/
Thanks for your help.
[ September 28, 2003: Message edited by: Marving Guildon ]
[ September 28, 2003: Message edited by: Marving Guildon ]