# Basic largest/smallest problem

• 09-21-2011, 02:07 AM
Acesplit
Basic largest/smallest problem
The goal is to get six numbers from the user and determine which is the largest and smallest, and display said numbers.
Here's what I have so far

Note: Can only use if, not if else or any other switch
I mean, I could do two if statements for every number but that seems highly excessive...
1 import java.util.Scanner;
2 public class gcook_SmallestLargest
3 {
4 public static void main(String args[])
5 {
6 Scanner input = new Scanner(System.in);
7 int smallest = 0,
8 largest = 0,
9 uinput = 0;
10 System.out.print("Please enter the first number: ");
11 uinput = input.nextInt();
12 smallest = uinput;
13 largest = uinput;
14 if(uinput < smallest && uinput != -99)
15 {
16 smallest = uinput;
17 }
18 if(uinput > largest)
19 {
20 largest = uinput;
21 }
22 System.out.print("The smallest is: " + smallest);
23 System.out.print("The largest is: " + largest);
24 }
25 }
• 09-21-2011, 02:29 AM
Fubarable
Re: Basic largest/smallest problem
I speak for all in wishing you good luck with this project. Please let us know how it goes.
• 09-21-2011, 03:24 AM
Acesplit
Re: Basic largest/smallest problem
Thanks but I honestly do not how to proceed..:s