Seems I'm struggling with this lesson.
I believe it outputs the second smallest number, however I keep failing on these conditions.
Could someone point me in the right direction? on why it's still not correct.
package en.codegym.task.pro.task04.task0410;
import java.util.Scanner;
/*
Second smallest number entered
*/
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
boolean x = true;
int secondSmallestInt = Integer.MAX_VALUE;
int min = Integer.MAX_VALUE;
int count = 0;
while (x){
if (s.hasNextInt())
{
int a = s.nextInt();
count++;
if (a < min) min = a;
if (a < min && a > secondSmallestInt)
{
secondSmallestInt = min;
min = a;
}else if ( a>min && a<secondSmallestInt){
secondSmallestInt = a;
}
} else if (s.hasNextLine()){
String exit = s.nextLine();
x = false;
}
}
if (count>1)
System.out.println(secondSmallestInt);
}
}