Write a program to input and store integer elements in a double dimensional array of size 3 x 4 and find the sum of all the elements.
import java.util.*;
class DDA
{
public static void main(String arg[])
{
int[][] num = new int[3][4];
int x = 0 ;
Scanner sk = new Scanner(System.in);
System.out.println("Enter all the
values ");
for(int i=0 ; i<3 ; i++)
{
for(int j=0 ; j<4 ; j++)
{
num[i][j] = sk.nextInt();
}
}
for(int i=0 ; i<3 ; i++)
{
for(int j=0 ; j<4 ; j++)
{
x = x + num[i][j] ;
}
}
System.out.println("The sum of all
the elements is : " +x) ;
}
}
Thanks sir HIMANSHU THAKUR
ReplyDelete