Define a class to accept values into a 4 × 4 integer array. Calculate and print the NORM of the array. NORM is the square root of sum of squares of all…

ICSE Class 10 Computer Applications PYQ · 2025 Paper · Section B

4Written · 2025 · Section B · 2025 Paper

Define a class to accept values into a 4 × 4 integer array. Calculate and print the NORM of the array.
NORM is the square root of sum of squares of all elements.

Show SolutionHide Solution↓
1	2	1	3
5	2	1	6
3	6	1	2
3	4	6	3

Sum of squares of elements = 1 + 4 + 1 + 9 + 25 + 4 + 1 + 36 + 9 + 36 + 1 + 4 + 9 + 16 + 36 + 9 = 201
NORM = Square root of 201 = 14.177446878757825

import java.util.Scanner;
class Norm{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a[][] = new int[4][4];
        int sum = 0;
        System.out.println("Enter array elements:");
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                a[i][j] = in.nextInt();
            }
        }
        
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                sum += a[i][j] * a[i][j];
            }
        }
        
        double root = Math.sqrt(sum);
        System.out.println("NORM = " + root);
    }
}
BlueJ output of Norm.java
← Previous questionNext question →

Browse the free Computer Applications sample bank