# Bigger and Smaller

• July 27th, 2010, 05:26 PM
dylgod
Bigger and Smaller
I am trying to write a program that reads an integer N that indicates the number of following inputs. The program then reads N integer values (larger than -999999 and smaller than 999999), finds the largest and the smallest values, and prints them. I don't fully understand this question and am left scratching my head as to what to do. Does anyone have any pointers for me?
• July 27th, 2010, 05:34 PM
helloworld922
Re: Bigger and Smaller
I would suggest reading this: Language Basics (The Java Language).

I would also suggest reading Numbers and Strings (The Java Language).

For reading in an integer, the simplest way is to use the Scanner class.

Code Java:

```Scanner reader = new Scanner(System.in); int myInteger = reader.nextInt();```

Once you have the integer, you can use the control structures talked about in the first link to determine if the number is within the correct range, and also figure out the min/max.
• July 27th, 2010, 07:48 PM
Norm
Re: Bigger and Smaller
Quote:

I don't fully understand this question
The problem has several points:
The program then reads N integer values
The values are checked to be between some values...
finds the largest value entered
finds the smallest value entered
prints the two values

Which ones don't you understand.
• July 28th, 2010, 09:04 AM
JavaPF
Re: Bigger and Smaller
Following on from helloworlds example:

Code Java:

```import java.util.Scanner;   public class BiggerAndSmaller {   public static void main(String args[]){   Scanner reader = new Scanner(System.in);   System.out.println("Enter first number: "); int myIntegerA = reader.nextInt();   System.out.println("Enter second number: "); int myIntegerB = reader.nextInt();     System.out.println(myIntegerA); System.out.println(myIntegerB); }   }```

Take a look at: The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
• July 28th, 2010, 09:18 AM
Norm
Re: Bigger and Smaller
Following on from JavaPF's code:
Code :

``` System.out.println("IntegerA=" + myIntegerA); System.out.println("IntegerB= " + myIntegerB);```

Iding the output can make it more readable.