Define a class to accept values into a 4 × 4 array and find and display the sum of each row. Example: A[][]={1,2,3,4),{5,6,7,8},{1,3,5,7},{2,5,3,1}} Output: sum of row 1=10 (1+2+3+4)
Advertisements
प्रश्न
Define a class to accept values into a 4 × 4 array and find and display the sum of each row.
Example:
A[][]={1,2,3,4),{5,6,7,8},{1,3,5,7},{2,5,3,1}}
Output:
sum of row 1=10 (1+2+3+4)
sum of row 2=26 (5+6+7+8)
sum of row 3=16 (1+3+5+7)
sum of row 4=11 (2+5+3+1)
थोडक्यात उत्तर
Advertisements
उत्तर
class sumrow
{
int x[][]=new int[4][4];
sumrow(int z[][])
{
x=z;
}
void calculate()
{
int r,c, s=0;
for(r=0;r<4;r++)
{
for(c=0;c<4;c++)
{
s=s+x[r][c];
}
System.out.println("sum of row="+r+"="+s);
s=0;
}
}
} shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
