83 lines
3.0 KiB
Java
Executable File
83 lines
3.0 KiB
Java
Executable File
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package programmingexam1_calebfontenot;
|
|
|
|
import java.util.Scanner;
|
|
|
|
/**
|
|
*
|
|
* @author ar114
|
|
*/
|
|
public class TwoLargerOfThe3 {
|
|
|
|
public static void main(String[] args) {
|
|
// Define vars
|
|
int _1, _2, _3; // Note to Markou: I find numbers easier to compare in my head than variables, hence my use of them here.
|
|
int firstLargest = 0, secondLargest = 0;
|
|
|
|
// Setup scanner
|
|
Scanner input = new Scanner(System.in);
|
|
while (true) {
|
|
// Prompt for input
|
|
System.out.print("Enter 3 numbers: ");
|
|
_1 = input.nextInt();
|
|
_2 = input.nextInt();
|
|
_3 = input.nextInt();
|
|
|
|
// Compute!
|
|
if (_1 <= _3 & _2 <= _3) { // Is _3 the largest?
|
|
firstLargest = _3; // Yes!
|
|
if (_2 >= _1) { // Is _2 larger than _1?
|
|
secondLargest = _2; //Then _2 must be the second largest.
|
|
} else {
|
|
secondLargest = _1; //Then _1 must be the second largest.
|
|
}
|
|
}
|
|
if (_3 <= _2 & _1 <= _2) { // Is _2 the largest?
|
|
firstLargest = _2; // Yes!
|
|
if (_3 >= _1) { //Is _3 larger than _1?
|
|
secondLargest = _3; // Then _3 must be the largest.
|
|
} else {
|
|
secondLargest = _1; // Then _1 must be the largest.
|
|
}
|
|
}
|
|
if (_3 <= _1 & _2 <= _1) { // Is _1 the largest?
|
|
firstLargest = _1; // Yes!
|
|
if (_3 >= _2) {// Is _3 larger than _2?
|
|
secondLargest = _3; // Then _3 must be the largest.
|
|
} else {
|
|
secondLargest = _2; // Then _2 must be the largest.
|
|
}
|
|
}
|
|
/*
|
|
if (_1 == _2 | _1 == _3 | _2 == _3) {
|
|
System.out.println("Some numbers equal. Running additional checks...");
|
|
if (_1 == _2) {
|
|
if (_1 > _3) { // Is _3 smaller than _1 and _2?
|
|
firstLargest = _1;
|
|
secondLargest = _3;
|
|
}
|
|
}
|
|
if (_1 == _3) {
|
|
if (_3 > _2) { // Is _2 smaller than _1 and _3?
|
|
firstLargest = _3;
|
|
secondLargest = _2;
|
|
}
|
|
}
|
|
if (_2 == _3) {
|
|
if (_3 > _1) { // Is _1 smaller than _2 or _3?
|
|
firstLargest = _3;
|
|
secondLargest = _1;
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
// Output
|
|
System.out.println("The first largest is " + firstLargest + " and the second largest is " + secondLargest);
|
|
}
|
|
}
|
|
}
|