-
Students
Hi,
I am trying to write a program that prompts for a number of students in a class and the size of teams to be formed, and displays how many teams can be formed and how many students are left without a team.
I have this so far, but am not really sure what to do next?
public class Students2_4
{
public static void main(String[]args)
{
int class, teams;
System.out.print("How many student in class")
class = Easyin.getInt();
System.out.print("How many teams to be formed")
teams = EasyIn.getInt();
Any suggestions would be helpful.
-
i dont understand why you want this line:
System.out.print("How many teams to be formed")
teams = EasyIn.getInt();
dont you want to ask the user what size the teams will be?
I would have thought that the user enters in the number of people, then the size of the teams, then the application will spit out the appropriate info.
Am i right in saying this?
A kram a day keeps the doctor......guessing
-
Well
at first i thought it was easy
but it's really tricked me for while
that's what got for you
I'm not using the EasyIn method because i don't know what it stand for
anyway this complil fine here
import java.io.*;
class Steam{
public static BufferedReader input=
new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] lalama)throws IOException{
System.out.println("enter the Number students ");
int snum=Integer.parseInt(input.readLine());
int p=snum;
System.out.println("enter the size of the team ");
int steam=Integer.parseInt(input.readLine());
int i=0;
do{ snum/=steam;}while(snum>snum%steam);
System.out.println("We can have "+snum%steam+" team but \n"+(p-steam*snum)+" students "
+"would be in no team ");
}
}
-
Kram
Yes you are right in saying what you said.
-
ok so ill give you some hints, some of these are covered by petert17's code. But here it goes:
when you divide 2 ints together you will get the closest result without any decimals, ie.
10/3 will give 3, and only 3, not 3.3333333etc...
so this can be used to give the number of teams that will fit into the class.
To get the leftovers, you need to use the mod (%) operator, this will give you the remainder after the division, ie.
10 % 3 will give 1, so 1 left over...
hope this hepls
A kram a day keeps the doctor......guessing
-
Thanks for hints i have now done it. Thanks.
-
Student Teams
Hi,
I got this to work last time but
i accidently deleted it and now
I am having a bit of a problem with the code,
public class Team
{
public static void main(String[]args)
{
int num,team;
{
System.out.println("enter the number of students ");
num = EasyIn.getInt();
System.out.println("enter the size of the team ");
team = EasyIn.getInt();
int p = num;
do{ num/=team;}while(num>num%team);
System.out.println("We can have "+num%team+" teams but \n"+(p-team*num)+" students "
+"would be in no team ");
}
}
}
Its compiling ok but its not doing what I thought it would.
something’s obviously missing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks