After multiplying all even numbers by 10, write code to sum all elements in each row and print the results. code used to multiply all even number by 10 below import java.util.Random; public class Main { public static void main(String[] args) { Random random = new Random(); // Generating a 5x5 matrix int[][] matrix = new int[5][5]; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { matrix[i][j] = random.nextInt(101); // from 0 to 100 } } // Printing the original matrix System.out.println("Original matrix: "); for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { System.out.print(matrix[i][j] + " "); } System.out.println(); } // Multiplying even numbers by 10 for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { if (matrix[i][j] % 2 == 0) { matrix[i][j] *= 10; } } } // Printing the modified matrix System.out.println("\nModified matrix: "); for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { System.out.print(matrix[i][j] + " "); } System.out.println(); } }
After multiplying all even numbers by 10, write code to sum all elements in
each row and print the results.
code used to multiply all even number by 10 below
import java.util.Random;
public class Main {
public static void main(String[] args) {
Random random = new Random();
// Generating a 5x5 matrix
int[][] matrix = new int[5][5];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
matrix[i][j] = random.nextInt(101); // from 0 to 100
}
}
// Printing the original matrix
System.out.println("Original matrix: ");
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
// Multiplying even numbers by 10
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
if (matrix[i][j] % 2 == 0) {
matrix[i][j] *= 10;
}
}
}
// Printing the modified matrix
System.out.println("\nModified matrix: ");
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
}


Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









