I have created a matrix in java using only loops. But I wanted to show the total of the row at the end. I have been trying to figure this out and I cannot come up with a solution. Any help would be appreciated.
This is the code I have so far
public class Main {
public static void main(String[] args) {
int num = 4;
int product = 0;
for (int i = 1; i <= num; i++) {
for (int j = 1; j <= num; j++) {
product = j * i;
System.out.printf("\t" + product);
}
System.out.println();
}
}
}
If I understand you correctly, you just need to implement something such as:
int total = 0;then on each cycle of the loop update accordingly…total = total + x;