Results 1 to 2 of 2

Thread: Help PLEASE :)

  1. #1
    I_think is offline Member
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Unhappy Java Program Question

    Just wondering how to Write a console Java program that asks the user to enter many whole numbers. The program should
    read these numbers until a negative number is entered. Then the program should print the least of
    the non-negative numbers entered. If the first number entered was negative, print "No numbers."
    Example output when some non-negative numbers entered:
    Enter a number: 45
    Enter a number: 23
    Enter a number: 2
    Enter a number: 32
    Enter a number: 54
    Enter a number: -1
    Least number is: 2
    Example output when no non-negative numbers entered:
    Enter a number: -1
    No numbers.

    please help me find out a way how to do this, it has had me stumped for a little while now :(

    hope someone can help me.
    Last edited by I_think; 05-04-2008 at 03:22 PM.

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    min = -1;
    input = 0;

    Java Code:
    while( input greater/equal 0 ){
         input = from user;
         compare input to -1
         if false, 
               if min is -1, assign to min
               else compare min to input,
                     if input is less than min
                           min = input;
    }
    
    show min value;
    freedom exists in the world of ideas

Posting Permissions

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