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

"Using Python, code to find the smallest and largest planet mass (if known), and plot these...
"Using Python, code to find the smallest and largest planet mass (if known), and plot these as two curves against the year of discovery" Basically looking to use data from an excel sheet where 'disc_year' and 'pl_mass' are columns of data; and code Python to find the maximum value of mass and the minimum value of mass for each year, then plot this as two curves. There are multiple planets for any given year hence multiple values for mass. Below...
. 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. Write a program that computes the smallest and largest of a set of values that...
1. Write a program that computes the smallest and largest of a set of values that are stored in an array. Ask the user for the set size (and hence the array size). Populate the array with user input.
1. Write a program that computes the smallest and largest of a set of values that...
1. Write a program that computes the smallest and largest of a set of values that are stored in an array. Ask the user for the set size (and hence the array size). Populate the array with user input. (Java language)
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.
The following variables are declared as follow: int Var1 = 9, Var2 = 2, Var3 =...
The following variables are declared as follow: int Var1 = 9, Var2 = 2, Var3 = 0; What will the output of the following statements be? Var3 = Va1 / Var2; Var2 = Var2 / Var1; out.print(Var3); out.print(Var2); int Var1 = 19, Var2 = 12, oy.print(Var1 % Var2); oy.print(Var1 % 3.0); 3. Var1 += 5; System.oy.print(Var1);
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).
PLEASE USE PYTHON CODE 2. Find the smallest positive (real) root of x^3-3.23x^2-5.54x+9.84 = 0 by...
PLEASE USE PYTHON CODE 2. Find the smallest positive (real) root of x^3-3.23x^2-5.54x+9.84 = 0 by the method of bisection
c++ input 10 number and calclute the midrange using (largest - smallest)/2.0. use for loop note...
c++ input 10 number and calclute the midrange using (largest - smallest)/2.0. use for loop note : dont use arrays
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT