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]. BlueJ output of Write a short program that doubles every element of an array A[4][4].](https://cdn1.knowledgeboat.com/img/sa10/c7-arrays-p35.jpg)
Answered By
1 Like
Related Questions
How are two-dimensional arrays represented in memory ?
Suppose A, B, C are arrays of integers of sizes m, n, m + n respectively. Give a program to produce a third array C, containing all the data of array A and B.
Let A(n x n) that are not diagonal array. Write a program to find the sum of all the elements which lie on either diagonal. For example, for the matrix shown below, your program should output 68 = (1 + 6 + 11 + 16 + 4 + 7 + 10 + 13):
From a two-dimensional array A[4][4], write a program to prepare a one-dimensional array B[16] that will have all the elements of A if they are stored in row-major form. For example, for the following array
the resultant array should be : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16