It compiles and runs fine, but when I run it it never ends. It keeps asking for a second integer. Here's the code.

Scanner get = new Scanner ( System.in );
                    System.out.print( "Please enter first integer: " );
                    int value = get.nextInt();
                    int smallest = value;
                    int largest = value;
                    for (int count = 0; count < 7; count++ )
                        {
                            System.out.println ( "Enter the second integer" );
                            value = get.nextInt();
                            System.out.println( "Enter the third integer" );
                            value = get.nextInt();
                            if ( value > largest ) largest = value;
                            if ( value < smallest ) smallest = value;
                            System.out.printf( "%d:%d",smallest, largest );
                        }
                }
}

Recommended Answers

All 4 Replies

You have a for loop that will prompt you for 2nd and 3rd input for a total of 7 times. Not sure why you glhave those two additional prompts if you are only checking after prompt 3

Well, I was just testing it and the total number of integers it asks me for is 8, so I figured i got the one up top and there is 7 more to go. So should i just remove the for statement or what do i do with it.

Inside the loop the print out statement should be Enter integer, the loop will ask this question the number of times you have stored in the loop, you will then assign the ints to an array and compare the values

int[] value = new int[7];

Scanner get = new Scanner ( System.in );
 for (int count = 0; count < value.length; count++ ){

                    System.out.print( "Please enter integer: " );
                    value[i] = get.nextInt();


                }
}

that should get you started

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.