Q6Java please Write a program that that computes the maximum

Q6-Java please

Write a program that that computes the maximum of two numbers. You need to follow the following instructions: Create a class called \"MaxProgram\'. The class MaxProgram has only one method called \"maxValue\". This method takes two integer numbers as parameters. The method returns the maximum of the two numbers, else it returns -1, If both numbers are equal. To test this class, create another class called \"Tester\", with a main method. In the main method, create an object of the \"MaxProgram\" class. From the created object, call the \"maxValue\" method, and give it any two numbers. Print the returned maximum number.

Solution

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg;

public class MaxProgram {
  
    public int maxValue(int a,int b)
    {
        if(a==b)
            return -1;
        else
            return a>b?a:b;
    }
}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg;

public class Tester {
  
    public static void main(String[] args)
    {
        MaxProgram mp = new MaxProgram();
        System.out.println(\"Maximum of 2 and 3 is : \"+mp.maxValue(2, 3));
        System.out.println(\"Maximum of 2 and 2 is : \"+mp.maxValue(2, 2));
    }
  
}

OUTPUT:

run:
Maximum of 2 and 3 is : 3
Maximum of 2 and 2 is : -1
BUILD SUCCESSFUL (total time: 0 seconds)

Q6-Java please Write a program that that computes the maximum of two numbers. You need to follow the following instructions: Create a class called \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site