Results 1 to 4 of 4
  1. #1
    Eaballard513 is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default I need help with a simple algorithm.

    I need to make a code that takes X number of students, and puts them in y number of buses. each buses holds 40 students.
    Java Code:
      {
             Scanner keyBoard = new Scanner(System.in);
             
             int busCompacity = 40;
             
             int numStudents = keyBoard.nextInt(); 
             
             int fullBuses = numStudents / busCompacity;
             
             int r1 = numStudents % busCompacity;
             
             int totalBuses = fullBuses + r1;
             
             System.out.println (   + numStudents + " Students will require " + totalBuses + " buses" );
          }
          
          
       }}
    this is what i have so far but it doesn't seem to work out .

    i need every integer besides 0 to be converted into 1 extra bus.

    I CANNOT USE IF STATEMENTS. EX.
    Java Code:
    if (r1>0) {
    r1=1 
    }


    i need an algorithm that does the same thing or just computes the problem correctly with any instance of students.

    PLEASE HELP
    Last edited by Eaballard513; 02-06-2012 at 12:14 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: I need help with a simple algorithm.

    it doesn't seem to work out
    Does the code compile? If not and you can't understand the compiler's messages, post them. Your code will need to define a class and give it a main() method.

  3. #3
    Eaballard513 is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default Re: I need help with a simple algorithm.

    that is just a portion of the code i have a main () method.

    it doesn't seem to work out
    <<< there is no compiler error the problem is that the algorithm doesnt have the right out come for all instances of students 1 to 1000

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: I need help with a simple algorithm.

    Closing. Duplicate of Help with simple algorithm problem

    @OP: Please don't do this. Stick to one thread per question.

Similar Threads

  1. Help with simple algorithm problem
    By Eaballard513 in forum New To Java
    Replies: 11
    Last Post: 02-06-2012, 05:11 AM
  2. Help with an Algorithm
    By Manfizy in forum New To Java
    Replies: 22
    Last Post: 07-03-2009, 08:16 AM
  3. O(log n) algorithm help !!!!!!
    By itseeker87 in forum New To Java
    Replies: 8
    Last Post: 09-09-2008, 06:12 PM
  4. Help with algorithm
    By susan in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 11:26 PM
  5. Help me with this algorithm
    By Marcus in forum Advanced Java
    Replies: 3
    Last Post: 07-02-2007, 02:30 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
  •