I am working on a code to read N user input numberb and then display the largest and the smallest of them. The inesgers have to fall in between -999999 and 999999, I have been tinkering with this for a few days now and can't seem to figure out how to make it work, here is my code
import java.util.*;
public class LabThree
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int totaldoubles;
int total, nextnum, max, min;
String answer;
do
{
System.out.println();
System.out.println("Enter a list of nonnegative integers");
System.out.println("When you are finished with the list, enter 1000000");
System.out.println();
System.out.println("I will tell you the largest and smallest integer");
totaldoubles = 0 ;
total = 0;
nextnum = keyboard.nextDouble();
max = nextnum;
min = nextnum;
while (nextnum != 1000000)
{
total = total + nextnum;
totaldoubles++;
nextnum = keyboard.nextDouble();
if (nextnum > max)
max = nextnum;
else if (nextnum < min)
min = nextnum;
}
if (totaldoubles >= -999999) System.out.println("The smallest number was: "+min);
System.out.println("The largest number was: " + max);
answer = keyboard.next();
}
}
}