Knowee
Questions
Features
Study Tools

You are provided with the below code.In main method invoke the findProduct method as instructed.public class Calculator{    public int findProduct(int x,int y)    {        return x*y;    }       public static void main(String a[])    {        int num1=10;        int num2=20;        Calculator calc=new Calculator();        //Call the method findProduct and store the return value in a variable product        Answer    }}

Question

You are provided with the below code.In main method invoke the findProduct method as instructed.public class Calculator{    public int findProduct(int x,int y)    {        return x*y;    }       public static void main(String a[])    {        int num1=10;        int num2=20;        Calculator calc=new Calculator();        //Call the method findProduct and store the return value in a variable product        Answer    }}

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

In the main method, you can call the findProduct method and store the return value in a variable named product as follows:

public class Calculator{ 
    public int findProduct(int x,int y) 
    { 
        return x*y; 
    } 

    public static void main(String a[]) 
    { 
        int num1=10; 
        int num2=20; 
        Calculator calc=new Calculator(); 
        //Call the method findProduct and store the return value in a variable product
        int product = calc.findProduct(num1, num2);
        System.out.println("The product is: " + product);
    }
}

In the above code, calc.findProduct(num1, num2); is used to call the findProduct method. The result of this method call is then stored in the variable product. The System.out.println statement is used to print the product to the console.

This problem has been solved

Similar Questions

Observe the below code.  You are provided with a class Calculator.  In the Main class, create an object for the class Calculator with reference name as "calcObj". class  Calculator{      int num1;      int num2;}public class Main{    public static void main(String args[])    {             Answer    }}

Observe the below code.  You are provided with a class Calculator.  in Calculator class, declare an attribute with name "result"  of data type float with default access specifier. class  Calculator{      float num1;      float num2;     Answer}public class Main{    public static void main(String args[])    {             Calculator calcObj=new Calculator();    }}

class Calculator {    public static int add(int a, int b) {        return a + b;    }    public static int add(int a, int b, int c) {        return a + b + c;    }}public class Main {    public static void main(String[] args) {        int result1 = Calculator.add(10, 20);        int result2 = Calculator.add(10, 20, 30);        System.out.println("Result1: " + result1 + ", Result2: " + result2);    }}a.Result1: 30, Result2: 60b.Result1: 20, Result2: 30c.None of the aboved.Compilation Error

public class Compute {public static void main (string args [ ]){int result, x ;x = 1 ;result = 0;while (x < = 10) {if (x%2 == 0) result + = x ;+ + x ;}System.out.println(result) ;}}

static double calculate( int num) { return num * 2 + 1;}public static void main( String[]args) {   int x = 8;   double result = calculate( x );}What is the value in result after this code is executed?

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.