Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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! image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions