outprintlnEnter a value for y int y scannextInt if x y SystemoutprintlnThe

Outprintlnenter a value for y int y scannextint if x

This preview shows page 1 - 3 out of 6 pages.

System.out.println("Enter a value for y:");int y = scan.nextInt();if (x <= y){System.out.println("The smallest value was " + x);}else{System.out.println("The smallest value was " + y);}}}Modify the code above so that it prompts the user to enter a third value for a variable z. Rewrite the logic so that the program prints out the smallest value contained in x, y, and z. Please note that you are not allowed to use math methods for this question. import java.util.*;
Image of page 1
public class Q1modify { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a value for x:"); int x = scan.nextInt(); System.out.println("Enter a value for y:"); int y = scan.nextInt(); System.out.println("Enter a value for z:"); int z = scan.nextInt(); { System.out.println("The smallest value was " + x); } { System.out.println("The smallest value was " + y); } { System.out.println("The smallest value was " + z); } } } Q1.2 Further modify the code so that it prompts the user for four integers (w, x, y, and z) and prints the smallest value contained in those variables. How hard would it be to modify the version of the program you wrote in Q1.1 to solve the four-variable problem?
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 6 pages?

  • Fall '12
  • DuiWei
  • smallest value

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture