C:\Users\ar114\Documents\NetBeansProjects\ProgrammingExam1_CalebFontenot\src\programmingexam1_calebfontenot\TwoLargerOfThe3.java |
package programmingexam1_calebfontenot;
import java.util.Scanner;
@author
public class TwoLargerOfThe3 {
public static void main(String[] args) {
int _1, _2, _3;
int firstLargest = 0, secondLargest = 0;
Scanner input = new Scanner(System.in);
while (true) {
System.out.print("Enter 3 numbers: ");
_1 = input.nextInt();
_2 = input.nextInt();
_3 = input.nextInt();
if (_1 <= _3 & _2 <= _3) {
firstLargest = _3;
if (_2 >= _1) {
secondLargest = _2;
} else {
secondLargest = _1;
}
}
if (_3 <= _2 & _1 <= _2) {
firstLargest = _2;
if (_3 >= _1) {
secondLargest = _3;
} else {
secondLargest = _1;
}
}
if (_3 <= _1 & _2 <= _1) {
firstLargest = _1;
if (_3 >= _2) {
secondLargest = _3;
} else {
secondLargest = _2;
}
}
if (_1 == _2 | _1 == _3 | _2 == _3) {
System.out.println("Some numbers equal. Running additional checks...");
if (_1 == _2) {
if (_1 > _3) {
firstLargest = _1;
secondLargest = _3;
}
}
if (_1 == _3) {
if (_3 > _2) {
firstLargest = _3;
secondLargest = _2;
}
}
if (_2 == _3) {
if (_3 > _1) {
firstLargest = _3;
secondLargest = _1;
}
}
}
System.out.println("The first largest is " + firstLargest + " and the second largest is " + secondLargest);
}
}
}