ICSE Class 10 Computer Applications Question 41 of 71

Arrays — Question 41

Back to all questions
41
Question

Question 35

Write a short program that doubles every element of an array A[4][4].

import java.util.Scanner;

public class KboatDDADouble
{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);

        int A[][] = new int[4][4];
        System.out.println("Enter elements of 4 x 4 array");
        
        for(int i = 0; i < 4; i++)  
        {
            System.out.println("Enter elements of row " + (i+1));
            for(int j = 0; j < 4; j++)
            {
                A[i][j] = in.nextInt();
            }
        }  
        
        System.out.println("Original array :");
        for(int i = 0; i < 4; i++)  
        {
            for(int j = 0; j < 4; j++)  
            {
                System.out.print(A[i][j] + "\t");
            }   
            System.out.println();
        }
        
        for(int i = 0; i < 4; i++)  
        {
            for(int j = 0; j < 4; j++)  
            {
                A[i][j] = A[i][j] * 2;
            }   
        }  
        
        
        System.out.println("Doubled Array");
        for(int i = 0; i < 4; i++)  
        {
            for(int j = 0; j < 4; j++)  
            {
                System.out.print(A[i][j] + "\t");
            }   
            System.out.println();
        }  
    }
}
Output
BlueJ output of KboatDDADouble.java
Answer