KnowledgeBoat Logo

Computer Applications

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 1

void 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

z=p×qz = p \times q

p=a+bcp = \dfrac{a + b}{c}

q=a+b+cq = a + b + c

Java

User Defined Methods

ICSE Sp 2025

6 Likes

Answer

public class KboatOverloadDisplay
{
    void display() {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 5; j++) {
                if (j % 2 == 0) {
                    System.out.print("1  ");
                } else {
                    System.out.print("2  ");
                }
            }
            System.out.println();
        }
    }
    
    void display(int n, int m) {
        if (m > n) {
            double q = m / n;
            System.out.println("Quotient: " + q);
        } else {
            int sum = 2 * n + 3 * m;
            System.out.println("Sum: " + sum);
        }
    }
    
    double display(double a, double b, double c) {
        double p = (a + b) / c;
        double q = a + b + c;
        double z = p * q;
        System.out.println("Z = " + z);
        return z;
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of 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 1 void 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 whereBlueJ output of 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 1 void 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 whereBlueJ output of 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 1 void 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 whereBlueJ output of 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 1 void 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 whereBlueJ output of 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 1 void 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 whereBlueJ output of 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 1 void 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 whereBlueJ output of 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 1 void 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

Answered By

3 Likes


Related Questions