This is a homework question and im still a newbie to java.
Write a code segment that computes the sum of all the values in marks.
This is my answer and it has compilation errors. Please help
class myArray{
public static void main(String args []){
int [] [] marks = {{1,2,3,4,5}, {6,7,8,9}, {10,11,12}};
for(int i = 0; i<marks.length; i++){
int sum = 0;
for(int j = 0; j <marks[i].length; j++) {
sum = sum + makrs[j][i];
}
}
System.out.println(sum);
}
}
There are two syntactical errors and one type.
int sum =0;aboveforloop as you need it outside the loop to print the valuemarks[j][i]tomarks[i][j]Correct the typo in the same line as above (
sum = sum + makrs[j][i];). You have typedmakrsin place ofmarks