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.
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.
i need an algorithm that does the same thing or just computes the problem correctly with any instance of students.
PLEASE HELP
Re: I need help with a simple algorithm.
Quote:
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.
Re: I need help with a simple algorithm.
that is just a portion of the code i have a main () method.
Quote:
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
Re: I need help with a simple algorithm.
Closing. Duplicate of http://www.java-forums.org/new-java/...tml#post264391
@OP: Please don't do this. Stick to one thread per question.