Results 1 to 3 of 3
  1. #1
    Acesplit is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default 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. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default 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. #3
    Acesplit is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default Re: Basic largest/smallest problem

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

Similar Threads

  1. Replies: 12
    Last Post: 09-08-2011, 06:03 PM
  2. Help with a largest sub-vector problem
    By caseballs in forum New To Java
    Replies: 5
    Last Post: 02-14-2011, 08:06 AM
  3. Array[] get smallest/largest value
    By bobocheez in forum New To Java
    Replies: 13
    Last Post: 09-10-2010, 12:16 AM
  4. Finding largest and smallest integer
    By mlhazan in forum New To Java
    Replies: 2
    Last Post: 01-12-2008, 11:30 PM
  5. ArrayList problem (finding largest no)
    By bugger in forum New To Java
    Replies: 3
    Last Post: 12-12-2007, 01:47 PM

Posting Permissions

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