Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following Java program that creates and uses a loop to populate a one-

ID: 3793284 • Letter: W

Question

Write the following Java program that creates and uses a loop to populate a one-dimensional array that holds the even numbers between 1 and 12; creates and uses a loop to populate a second one-dimensional array that holds the odd numbers between 1 and 12; creates a two-dimensional array that holds the values of the products of the two one-dimensional arrays. Example...the value of [0][0] in the two dimensional array should be the value of the [0] subscript in the even array multiplied by the [0] subscript in the odd array.   The value of the [1][1] spot in the two dimensional array should be the value of the [1] subscript in the even array multiplied by the [1] subscript in the odd array. Pass the two-dimensional array to a method which outputs the values of the two dimensional array to the screen in an organized fashion so it is clear which values are which. Remember, you need to show as output the entire multiplication table...a total of 36 values. Also, please show the appropriate column headings and row headings.

This is what I have however I can not get the original arrays (even and odd) to print as the heading for the column and row.

mport java.util.*;
public class Multiply {

public static void main(String args[]){
//Variable for array values
int even[] = new int[6];
int odd[] = new int[6];
int i, j = 0;
for(i = 1; i <= 12; i += 2){
odd[j] = i;
even[j] = i + 1;
j++;
}

//New varrible for product
int product[][] = new int[6][6];

for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++){
  
//Define value of new variable
product[i][j] = odd[i] * even[j];
}
}

for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++){
  
//Print out arrays
System.out.print(product[i][j] + " ");
if(product[i][j] < 99) System.out.print(" ");
if(product[i][j] < 9) System.out.print(" ");
}
System.out.println();
}
}
}

Explanation / Answer

Hi buddy, please find the below java program.

class Main {
public static void main(String args[]){
//Variable for array values
int even[] = new int[6];
int odd[] = new int[6];
int i, j = 0;
for(i = 1; i <= 12; i += 2){
odd[j] = i;
even[j] = i + 1;
j++;
}
//New varrible for product
int product[][] = new int[6][6];
for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++){
  
//Define value of new variable
product[i][j] = odd[i] * even[j];
}
}
  
//Heading for column
System.out.print(" ");
for(i=0; i<6 ;i++){
System.out.print("("+(2*(i)+1)+") ");
}
System.out.println();
for(i = 0; i < 6; i++){
//Heading for ROW
System.out.print("("+(2*(i+1))+") ");
for(j = 0; j < 6; j++){
  
//Print out arrays
System.out.print(product[i][j] + " ");
if(product[i][j] < 99) System.out.print(" ");
if(product[i][j] < 9) System.out.print(" ");
}
System.out.println();
}
}
}

OUTPUT :

(1) (3) (5) (7) (9) (11)
(2) 2 4 6 8 10 12   
(4) 6 12 18 24 30 36   
(6) 10 20 30 40 50 60   
(8) 14 28 42 56 70 84   
(10) 18 36 54 72 90 108
(12) 22 44 66 88 110 132