[HD Pg 0, Sec. 7.9.0 - exercises]

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
bankimis
Posts: 1
Joined: Sun Mar 08, 2020 2:55 am
Contact:

[HD Pg 0, Sec. 7.9.0 - exercises]

Post by bankimis »

public class Main {

public static void main(String[] args) {
int sumRow = 0;
int sumColumn = 0;
int [][] myInts = {{1,2},{1,2,3},{1,2,3}};
for (int i =0;i<myInts.length;i++) {
for (int j=0;j<myInts.length;j++){
sumRow = sumRow + myInts[j];
}
System.out.println(sumRow);

}
}
}

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 7.9.0 - exercises]

Post by admin »

Are you asking whether this is the correct answer?
If you like our products and services, please help us by posting your review here.

enthunoob
Posts: 60
Joined: Thu Apr 15, 2021 12:21 pm
Contact:

Re: [HD Pg 0, Sec. 7.9.0 - exercises]

Post by enthunoob »

Typo in question 6:
6. The following code contains a mistake that is quite common while using nested for loops. Identify the problem, fix it and print out all the elements of chars array.

String[][] chars = new String[2][];
chars[0] = new String[2];
chars[1] = new String[4];
char cha = 97;
for (char c = 0; c < chars.length; c ++) {
for (char ch = 0; ch < chars.length; ch++) {
chars[c][ch] = "" + cha;cha++;
}
}

What will happen if char[0] is initialized as new String[1] instead of new String[2]?
Surely chars[o] is meant to be written there.

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests