Results 1 to 4 of 4
- 02-05-2012, 11:09 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
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.
this is what i have so far but it doesn't seem to work out .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" ); } }}
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 HELPLast edited by Eaballard513; 02-05-2012 at 11:14 PM.
- 02-05-2012, 11:18 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Re: I need help with a simple algorithm.
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.it doesn't seem to work out
- 02-05-2012, 11:36 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Re: I need help with a simple algorithm.
that is just a portion of the code i have a main () method.
<<< there is no compiler error the problem is that the algorithm doesnt have the right out come for all instances of students 1 to 1000it doesn't seem to work out
- 02-05-2012, 11:37 PM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
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
-
Help with simple algorithm problem
By Eaballard513 in forum New To JavaReplies: 11Last Post: 02-06-2012, 04:11 AM -
Help with an Algorithm
By Manfizy in forum New To JavaReplies: 22Last Post: 07-03-2009, 07:16 AM -
O(log n) algorithm help !!!!!!
By itseeker87 in forum New To JavaReplies: 8Last Post: 09-09-2008, 05:12 PM -
Help with algorithm
By susan in forum New To JavaReplies: 1Last Post: 07-13-2007, 10:26 PM -
Help me with this algorithm
By Marcus in forum Advanced JavaReplies: 3Last Post: 07-02-2007, 01:30 PM


LinkBack URL
About LinkBacks

Bookmarks