Results 1 to 6 of 6
  1. #1
    filem_funk is offline Member
    Join Date
    Nov 2009
    Location
    manila, philippines
    Posts
    3
    Rep Power
    0

    Default java loop problem

    GUYS CAN YOU HELP ME ON THIS..?
    IT WOULD BE A GREAT HELP ON ME

    A program that asks the user for the low and high integer in a range of integers. The program then asks the user for integers to be added up. The program computes two sums:

    1.The sum of integers that are in the range(inclusive)
    2.The sum of the integers that are outside the range.

    The user signals the end of input with a 0.
    Low end of range: 20
    High end of range: 50

    Sum of In range values
    Sum of out of range values

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    What have you done so far?

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default

    They've posted here...;)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    The core of your solution is supposed to look something like this:

    Java Code:
    if (number >= lo && number <= hi)
       sumInRange+= number;
    else
       sumOutRange+= number;
    All you have to do is add a bit of riff-raff around this.

    kind regards,

    Jos

  5. #5
    filem_funk is offline Member
    Join Date
    Nov 2009
    Location
    manila, philippines
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    The core of your solution is supposed to look something like this:

    Java Code:
    if (number >= lo && number <= hi)
       sumInRange+= number;
    else
       sumOutRange+= number;
    All you have to do is add a bit of riff-raff around this.

    kind regards,

    Jos
    tnx guys

    can I use the for


    try{
    for(x;x<y;x++)
    sumInRange=sum +x;
    }
    sumOutRange=sum+y;

    will it work?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Help with a loop-like problem
    By Jnoobs in forum New To Java
    Replies: 1
    Last Post: 10-14-2009, 01:15 AM
  2. Problem with loop
    By Tykk in forum New To Java
    Replies: 7
    Last Post: 10-04-2009, 10:26 PM
  3. Replies: 3
    Last Post: 07-18-2009, 01:26 PM
  4. Problem to use different for loop to add up
    By matt_well in forum New To Java
    Replies: 6
    Last Post: 08-03-2008, 10:24 PM
  5. For loop problem
    By mcal in forum New To Java
    Replies: 32
    Last Post: 01-25-2008, 03:51 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
  •