Question

In: Computer Science

1. in the code below, 2 variables (largest and smallest) are declared. use these variables to...

1. in the code below, 2 variables (largest and smallest) are declared. use these variables to store the largest and smallest of three integer values. you must decide what other variables you will need and initialize them if appropriate.

2. write the rest of the program using assignment statements, if statements, or if else statements as appropriate. There are comments in the code that tell you where you should write your statements

3. compile and execute. Output should be:

The largest value is 78

The smallest value is -50

// LargeSmall.java - This program calculates the largest and smallest of three integer values.


public class LargeSmall
{
   public static void main(String args[])
   {
       // This is the work done in the housekeeping() method
       // Declare and initialize variables here.
       int largest;       // Largest of the three values.
       int smallest;       // Smallest of the three values.
      
       // This is the work done in the detailLoop() method
       //Write assignment, if, or if else statements here as appropriate.      
  
      
       // This is the work done in the endOfJob() method  
       // Output largest and smallest number.
       System.out.println("The largest value is " + largest);
       System.out.println("The smallest value is " + smallest);
   }
}   

Solutions

Expert Solution

Hi, Please find my implementation.

Please let me know in case of any issue.

import java.util.Scanner;

public class LargeSmall

{

   public static void main(String args[])

   {

       // This is the work done in the housekeeping() method

       // Declare and initialize variables here.

       int largest; // Largest of the three values.

       int smallest; // Smallest of the three values.

       // This is the work done in the detailLoop() method

       //Write assignment, if, or if else statements here as appropriate.

       Scanner keyboard = new Scanner(System.in);

       System.out.println("Enter three integers: ");

       int x = keyboard.nextInt();

       int y = keyboard.nextInt();

       int z = keyboard.nextInt();

      

       if(x > y){

           largest = x;

           smallest = y;

       }else{

           largest = y;

           smallest = x;

       }

      

       if(largest < z)

           largest = z;

       else if(smallest > z)

           smallest = z;

      

       keyboard.close();

       // This is the work done in the endOfJob() method

       // Output largest and smallest number.

       System.out.println("The largest value is " + largest);

       System.out.println("The smallest value is " + smallest);

   }

}

/*

Sample run:

Enter three integers:

4 5 1

The largest value is 5

The smallest value is 1

*/


Related Solutions

. For n = 2 look at the smallest and largest sample means. How close is...
. For n = 2 look at the smallest and largest sample means. How close is each of these sample means to the population mean? Use the formula x − . This difference is called the sampling error. Do the same for n = 3 and n = 4. What do you notice as n gets larger?
1. Name the specializations of the small intestine from largest to smallest structure. What is their...
1. Name the specializations of the small intestine from largest to smallest structure. What is their purpose? 2. Name the subdivisions of the small and large intestines in the complete and correct sequence. 3. Draw and label the parts of the uriniferous tubule. Include all parts of the nephron and the collecting duct. List the sequence of filtrate moving through the nephron to collecting duct in the correct sequence.
1. List each body habitus from smallest to largest and describe each (1 point).
1. List each body habitus from smallest to largest and describe each (1 point).
1. what is the best wavelength to use to examine the smallest visible samples? Why? 2....
1. what is the best wavelength to use to examine the smallest visible samples? Why? 2. If the resolution of an FTIR depends on the distance the mirror travels, why are relatively long moving distances such as 2 or 4 cm not used? What is the trade-off? 3. Which of the three contributing factors to band broadening in chromatography is independend of the flow rate? Explain why.
Please put the arteries in order from the LARGEST to SMALLEST diameter.       -   ...
Please put the arteries in order from the LARGEST to SMALLEST diameter.       -       1.       2.       3.       Arterioles       -       1.       2.       3.       Elastic (Conducting) arteries       -       1.       2.       3.       Muscular Arteries 1 points    QUESTION 8 Please put the vessels in the correct order from when a blood cell leaves the...
1. For each set of atoms/ions, write them in increasing order of size (smallest to largest)...
1. For each set of atoms/ions, write them in increasing order of size (smallest to largest) a. Mg2+, Se2- , S2- , K+ , Ca2+ b. Ga, Si, Rb, N, In c. A2+, B+ , C, D- , E2- if these elements are isoelectronic (same number of electrons) d. Put the following elements, S, Ba, Bi, Cl, Te, Ar in order of increasing ionization energy, and increasing electron affinity. 2. The following questions involve the following atoms: Ge, As, K,...
Develop a recursive algorithm to find the smallest and largest element in an array and trace...
Develop a recursive algorithm to find the smallest and largest element in an array and trace the recursive function with appropriate message. using c++ add comment to the code
Exercise1. Selected transactions for the SJH Company are listed below. 1. Collected accounts receivable. 2. Declared...
Exercise1. Selected transactions for the SJH Company are listed below. 1. Collected accounts receivable. 2. Declared and paid dividends on ordinary shares. 3. Sold long-term investments for cash. 4. Issued ordinary shares for equipment. 5. Repaid five year note payable. 6. Paid employee wages. 7. Converted bonds payable to ordinary shares. 8. Acquired long-term investment with cash. 9. Sold buildings and equipment for cash. 10. Sold merchandise to customers. Instructions Classify each transaction as either (a) an operating activity, (b)...
1) Complete the Table below. 2) Based on the completed table what is the largest additional...
1) Complete the Table below. 2) Based on the completed table what is the largest additional order that could be accepted for delivery for the end of week 8? Order Policy = 450 Beginning Inventory = 425 Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 Week 8 Forecast 460 400 440 420 400 465 410 425 Orders 350 425 400 435 410 325 250 175 Projected On-Hand Master Production Schedule Available-to-Promise
1-a need Explanation of the variables of the Bellman equation ?(?,?)=??? ?(?)+??(?′,?′) 2-When to use it?...
1-a need Explanation of the variables of the Bellman equation ?(?,?)=??? ?(?)+??(?′,?′) 2-When to use it? 3-What are the main methods used for solving using the Bellman equation? 4-Give an economic example to which the Bellman equation can be applied and how
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT