KnowledgeBoat Logo
|

Computer Applications

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

Java

Java Arrays

3 Likes

Answer

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();
        }  
    }
}

Variable Description Table

Program Explanation

Output

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

Answered By

3 Likes


Related Questions