Thread: Basic largest/smallest problem

1. Member
Join Date
Sep 2011
Posts
2
Rep Power
0

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 }

2. Re: Basic largest/smallest problem

I speak for all in wishing you good luck with this project. Please let us know how it goes.

3. Member
Join Date
Sep 2011
Posts
2
Rep Power
0

Re: Basic largest/smallest problem

Thanks but I honestly do not how to proceed..:s

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•