ex4filledin - num2 = input.nextInt...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* class FindMaxOfThree * * Purpose: Using conditional statements */ import java.util.Scanner; // use the Java built-in class Scanner public class FindMaxOfThree { // main method is always the first Java runs in your program public static void main(String args[]) { // You can declare different variables with one line int num1, num2, num3, max; // Read in the three numbers Scanner input = new Scanner( System.in ); System.out.print("Enter the first number:"); num1 = input.nextInt(); System.out.print("\nEnter the second number:");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: num2 = input.nextInt(); System.out.print("\nEnter the third number:"); num3 = input.nextInt(); // initialize max - this means we don't check for num1 max max = num1; // see if num2 is max if ((num2 > num1) && (num2 >= num3)) { max = num2; } // see if num3 is max if ((num3 > num1) && (num3 > num2)) { max = num3; } System.out.printf("%d is the largest number\n",max); } // end of main } // end of class FindMaxOfThree...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Ask a homework question - tutors are online