Question: I have this code in java: and im trying to call it in the main class called Ecercise 1. I had another class already in

I have this code in java: and im trying to call it in the main class called Ecercise 1. I had another class already in the main and it works perfectly. not sure whats going on...mainly need help in calling the (Part2) class in the main! I have this code in java: and im trying to call it

public class Part2 {

int[][] myArray2 = new int[8][10];{

// Fill elements of array from 1-80 using i, j

for (int i = 0; i

for (int j = 0; j

myArray2[i][j] = (j + 1) + (i * 10);

}

}

}

public static void printArrayValues(int[][] myArray2) {

System.out.println("myArray2 = {");

for (int i = 0; i

{

System.out.print("{");

for (int j = 0; j

System.out.print(myArray2[i][j]);

if (j != 9) {

System.out.print(",");

}

}

if (i != 9) {

System.out.println("},");

} else {

System.out.println("}");

}

}

System.out.println("};");

}

public static void displayArrayTotal(int[][] myArray2) {

int sum = 0; // initialise sum to 0

for (int[] i : myArray2) // foreach loop to iterate through outer array

{

for (int j : i) // foreach loop to iterate through inner array / individual elements

{

sum += j; // add to sum

}

}

// display output

System.out.println("Sum of all elements of myArray2 is " + sum);

}

}

*ExerciseOne.java Part1java "Part2.java Part.java 2 public class ExerciseOne { public static void main(String arg[]) [ 7 Part1 array1 = new Part1(); 8 array.printArrayValues ); 9 array1.displayArrayTotal); 11 System.out.println("); 12 14 Part2 array2 = new Part2(); 15 array2.printArrayValues (myArcay2); 16 array.displayArrayTotal (mvArray; 17 18 19 20 21

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!