Results 1 to 3 of 3
Thread: Basic largest/smallest problem
- 09-21-2011, 01:07 AM #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 }
-
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, 02:24 AM #3
Member
- Join Date
- Sep 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
How to display largest and smallest numbers entered..?
By Art_88 in forum New To JavaReplies: 12Last Post: 09-08-2011, 05:03 PM -
Help with a largest sub-vector problem
By caseballs in forum New To JavaReplies: 5Last Post: 02-14-2011, 07:06 AM -
Array[] get smallest/largest value
By bobocheez in forum New To JavaReplies: 13Last Post: 09-09-2010, 11:16 PM -
Finding largest and smallest integer
By mlhazan in forum New To JavaReplies: 2Last Post: 01-12-2008, 10:30 PM -
ArrayList problem (finding largest no)
By bugger in forum New To JavaReplies: 3Last Post: 12-12-2007, 12:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks