Computer Applications
Define a class to accept values into 4x4 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)
Java
Java Arrays
ICSE Sp 2025
5 Likes
Answer
import java.util.Scanner;
public class KboatDDARowSum
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[][] = new int[4][4];
System.out.println("Enter 4x4 DDA elements:");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
arr[i][j] = in.nextInt();
}
}
for (int i = 0; i < 4; i++) {
int rowSum = 0;
for (int j = 0; j < 4; j++) {
rowSum += arr[i][j];
}
System.out.println("Sum of Row" + (i+1)
+ " = " + rowSum);
}
}
}
Variable Description Table
Program Explanation
Output
Answered By
2 Likes
Related Questions
Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search element not found" using Binary search technique.
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.
Define a class to accept a string and convert the same to uppercase, create and display the new string by replacing each vowel by immediate next character and every consonant by the previous character. The other characters remain the same.
Example:
Input : #IMAGINATION@2024
Output : #JLBFJMBSJPM@2024Define a class to accept a number and check whether it is a SUPERSPY number or not. A number is called SUPERSPY if the sum of the digits equals the number of the digits.
Example1:
Input: 1021 output: SUPERSPY number [SUM OF THE DIGITS = 1+0+2+1 = 4, NUMBER OF DIGITS = 4 ]
Example2:
Input: 125 output: Not an SUPERSPY number [1+2+5 is not equal to 3]
Define a class to overload the method display() as follows:
void display(): To print the following format using nested loop.
1 2 1 2 1
1 2 1 2 1
1 2 1 2 1void display (int n, int m) : To print the quotient of the division of m and n if m is greater than n otherwise print the sum of twice n and thrice m.
double display (double a, double b, double c) — to print the value of z where