In: Computer Science
JAVA CODE FILL IN THE BLANKS
you are to complete the skeleton program by completing
* the To Do sections. I would suggest doing this a
* little bit at a time and testing each step before you
* go on to the next step.
*
* Add whatever
code is necessary to complete this assignment
*********************************************************************/
//Add whatever code is necessary to complete this assignment
public class Methods
{
public static void main(String[] args)
{
//create two integer variables
below
//ask the user to enter numbers
into each of the variables
(
//call the max method to determine
which number is the biggest
//and then display the result to
the screen in a message that looks like...
//"The highest number you entered
was X"
//call the difference method to
determine the difference between the two numbers
//and then display the result to
the screen in a message that looks like...
//"The difference between X and Y
is Z" (where X is the first number,
//Y is the second number and Z is
the difference)
//***The difference should always
be a positive value***
}//end main
//write a max method here. It should accept two
numbers and return the highest
//of those two numbers
//write a difference method here. It should accept two
numbers and return the difference
//between the two numbers. *** The difference must
always be a positive number. ***
}//end Methods
import java.util.Scanner;
//Add whatever code is necessary to complete this assignment
public class Methods {
public static void main(String[] args) {
// create two integer variables
below
int n1, n2;
Scanner sc = new
Scanner(System.in);
// ask the user to enter numbers
into each of the variables (
System.out.println("Enter 2 values:
");
n1 = sc.nextInt();
n2 = sc.nextInt();
System.out.println("The highest
number you entered was " + max(n1, n2));
// call the max method to determine
which number is the biggest
// and then display the result to
the screen in a message that looks like...
// "The highest number you entered
was X"
System.out.printf("The difference between %d and is %d is %d", n1, n2, difference(n1, n2));
// call the difference method to
determine the difference between the two
// numbers
// and then display the result to
the screen in a message that looks like...
// "The difference between X and Y
is Z" (where X is the first number,
// Y is the second number and Z is
the difference)
// ***The difference should always
be a positive value***
}// end main
// write a max method here. It should accept two
numbers and return the highest
// of those two numbers
private static int max(int a, int b) {
return (a > b) ? a : b;
}
// write a difference method here. It should accept
two numbers and return the
// difference
// between the two numbers. *** The difference must
always be a positive number.
// ***
private static int difference(int a,int b) {
return Math.abs(a-b);
}
}// end Methods
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me