0

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 );
                        }
                }
}
3
Contributors
4
Replies
39
Views
3 Years
Discussion Span
Last Post by tricket_7
0

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

0

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.

0

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

0
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

Edited by tricket_7: error in post

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.