Computer Applications
Define a class to accept values into a 3x3 integer array and print the product of each row elements.
Example:
| 3 | 1 | 2 |
| 4 | 2 | 1 |
| 5 | 1 | 2 |
Output:
Row 0 – 6
Row 1 – 8
Row 2 – 10
Java
Java Arrays
5 Likes
Answer
import java.util.Scanner;
public class RowProduct {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] arr = new int[3][3];
System.out.println("Enter 9 integers for the 3x3 array:");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
arr[i][j] = sc.nextInt();
}
}
for (int i = 0; i < 3; i++) {
int product = 1;
for (int j = 0; j < 3; j++) {
product *= arr[i][j];
}
System.out.println("Row " + i + " – " + product);
}
}
}Output

Answered By
1 Like
Related Questions
class perform { int m; String name; perform(int x, String y) { m=x; name=y; } void print() { System.out.print(name + " " + m); } public static void main() { perform ob1=new perform(95 , "Xavier"); ob1.print(); } }(a) Give the output of the code given above.
(b) Name the type of the constructor used.
Define a class with following specifications.
class name: Hotel
Member variables:
String name – stores name of customer name
long mobno – stores mobile number
int days – stores number of days customer stayed in hotel
int bill – stores customer billMember method:
void input() – input values using Scanner class methods only
void charge() – calculate bill as per the following criteriadays charge/day first 3 days 1000 Rs/ day next 4 days 900 Rs/day > 7 days 800 Rs/day bill = bill + gst (18% of bill)
void print() - Display customer name, mobile number and bill.
Invoke all the above methods in main method with the help of an object.
Define a class to overload the method transform as follows:
int transform(int n) – to return the sum of the digits of the given number
Example: n = 458
output : 17void transform(String s) – to convert the given String to upper case and print
Example: if S = “Blue”
Output : BLUEvoid transform (char ch) – to print the character ch in 3 rows and 3 columns using nested loops.
Example: if ch = ‘@’
Output :@@@ @@@ @@@Define a class to accept a string. Check if it is a Special String or not.
A String is Special if the number of vowels equals to the number of consonants.
Example: MINE
Number of vowels = 2
Number of Consonants = 2