Question

In: Computer Science

JAVA CODE FILL IN THE BLANKS you are to complete the skeleton program by completing *...

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

Solutions

Expert Solution


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


Related Solutions

Fill-In-The-Blanks 13. Complete the code by filling in the blanks for each question below. (Length of...
Fill-In-The-Blanks 13. Complete the code by filling in the blanks for each question below. (Length of blank doesn’t matter.) a) Print out the contents of the array airlines. #include #include ________________ using namespace std; int main () { string airlines[] = {"american","pan-am","southwest"}; for (int i = 0;_______________;i++) cout << ____________ << endl; return 0; } b) Read in 5 integers from the user and write them back out in reverse order int numbers[5]; for(int i = 0; ___________; _________) cin...
Fill in the blanks in the MATLAB code below.
Fill in the blanks in the MATLAB code below. (Do not type unnecessary words or blank spaces in your response. The correct answers are case-sensitive.) % Consider a row vector v. % Complete the lines of code below to find the average and standard deviation of the elements of vector v such that these two values are assigned to variables M and S, respectively. E = G =
Fill in the blanks to complete the following table.
Fill in the blanks to complete the following table.SymbolIon FormedNumber of Electrons in IonNumber of Protons in IonF__________9Te_____54_____II−_______________Mg2+_____12Part AComplete the first column of the table.Express your answer as a chemical symbol.Part BComplete the second column of the table.Express your answer as ions. Enter your answers in order given in the table, from top to bottom, separated by a comma.Part CComplete the third column of the table.Express your answer as integers. Enter your answers in order given in the table, from...
Fill in the following blanks for java code::: import java.util.NoSuchElementException; public class CircularQueue<E> {    private...
Fill in the following blanks for java code::: import java.util.NoSuchElementException; public class CircularQueue<E> {    private E[] queue;    private int front = 0, rear = 0;    private static final int DEFAULT_CAPACITY = 5;       public CircularQueue(int capacity)    {    queue = (E[]) new Object[capacity + 1];    }       public CircularQueue()    {        this(DEFAULT_CAPACITY); }       //Add a method that will determine if the queue is empty. Recall that the queue is...
C++ Fill in the blanks please You are required to fill in the blanks in this...
C++ Fill in the blanks please You are required to fill in the blanks in this program. Consider that: -In main, the variables price and quantity were given the names of p (double) and q (int), respectively. -In the getData function, the parameters associated with the main variables p and q were called pp and pq, respectively. // Prototype: Do not include the names // of the variables in the prototype void getData (FILLTHEBLANK , FILLTHEBLANK); int main () {...
JAVA * This is a skeleton file. Complete the functions below. You * may also edit...
JAVA * This is a skeleton file. Complete the functions below. You * may also edit the function "main" to test your code. * * You should not use any loops or recursions. Your code needs to run in * constant time. It is OK if your testing code has loops (like in checkInvariants). * * You must not add fields or static variables. As always, you must not change * the declaration of any method nor the name of...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text label and a button.When the program begins, the label displays a 0. Then each time the button is clicked, the number increases its value by 1; that is each time the user clicks the button the label displays 1,2,3,4............and so on.
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that...
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that it is equivalent to the following C code. int counter; int x = 5; int y = 6; for (counter =10; counter >0;counter--) IF(X==Y) Y = Y + 1 ; ELSE Y = Y + 2} Fill in the blanks in the following code: MOV__________ ;loop counter into r0-ten times round the loop MOV__________ ;Value of y loaded into r1 MOV__________ ;Value of x...
The following program is used to sum arrays. Fill in blanks of the following program to...
The following program is used to sum arrays. Fill in blanks of the following program to complete the program and make the output is: s = 150. #include <iostream.h> class Arr { int *a,n; public: Arr():a(0),n(0){} Arr(int *aa, int nn) {n=nn; a=new int [n]; for(int i=0;i<nn;i++) *(a+i)=*(aa+i); } ~Arr(){delete a;} _____________ {return *(a+i);} }; void main() { int b [5]={10,20,30,40,50}; Arr a1(b,5); int i=0,s=0; _____________ s+=a1.GetValue(i); cout<<"s="<<s<<endl; }
JAVA ONLY - Complete the code import java.util.Scanner; /** * This program will use the HouseListing...
JAVA ONLY - Complete the code import java.util.Scanner; /** * This program will use the HouseListing class and display a list of * houses sorted by the house's listing number * * Complete the code below the numbered comments, 1 - 4. DO NOT CHANGE the * pre-written code * @author * */ public class HouseListingDemo { public static void main(String[] args) { Scanner scan = new Scanner(System.in); HouseListing[] list; String listNumber, listDesc; int count = 0; double listPrice; String...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT