[java] LargestNum

Viewer

copydownloadembedprintName: LargestNum
  1. /*The purpose of this program is to identify the 
  2. largest number out of three ints entered by the user.
  3. Created w/ VSCode
  4. */
  5.  
  6. import java.util.Scanner;
  7.  
  8. public class LargestNum {
  9.    public static void main(String[] args) {
  10.       Scanner keyboard = new Scanner(System.in);
  11.       int num1;
  12.       int num2;
  13.       int num3;
  14.  
  15.       System.out.println("Enter a number");
  16.       num1 = keyboard.nextInt();
  17.  
  18.       System.out.println("Enter another number");
  19.       num2 = keyboard.nextInt();
  20.  
  21.       System.out.println("Enter a third number");
  22.       num3 = keyboard.nextInt();
  23.    
  24.  
  25.       // TO DO: Complete the following code to determine which of the three numbers are the largest
  26.       //Make note of any assumptions that you are making
  27.  
  28.       if (       ) { //fill in this if statement (in parens), for the condition where num1 is the largest
  29.          System.out.println(num1+" is the largest num.");
  30.       }
  31.       else if (    ) { //fill in this if statement, for the condition where num2 is the largest
  32.          System.out.println(num2 +" is the largest num.");
  33.       }
  34.       else { //since num1 and num2 weren't largest, num3 is largest by default
  35.          System.out.println(num3 +" is the largest num.");
  36.       } 
  37.       keyboard.close();
  38.    }
  39. }

Editor

You can edit this paste and save as new:


File Description
  • LargestNum
  • Paste Code
  • 28 Sep-2022
  • 1.25 Kb
You can Share it: