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);
}
}
}
[HD Pg 0, Sec. 7.9.0 - exercises]
Moderator: admin
-
- Posts: 1
- Joined: Sun Mar 08, 2020 2:55 am
- Contact:
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 0, Sec. 7.9.0 - exercises]
Are you asking whether this is the correct answer?
If you like our products and services, please help us by posting your review here.
-
- Posts: 60
- Joined: Thu Apr 15, 2021 12:21 pm
- Contact:
Re: [HD Pg 0, Sec. 7.9.0 - exercises]
Typo in question 6:
Surely chars[o] is meant to be written there.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]?
Who is online
Users browsing this forum: No registered users and 55 guests