Mr. Smith has a fifth-grade class of 20 students - ten boys and ten girls. Durin
ID: 3562269 • Letter: M
Question
Mr. Smith has a fifth-grade class of 20 students - ten boys and ten girls. During a gym period, he decides to divide the class into two teams - blue and red - by having the children stand in a circle and then counting around the circle. Every fifth student is told to leave the circle and become a member of the blue team. After ten children have been "counted out" for the blue team in this way, the ten remaining children become the red team. Surprisingly, the blue team turns out to be all boys and the red team turns out to be all girls. How were the children originally arranged in the circle so that this happened? using ArrayList
Here is what the answer would be if every FOURTH
student were told to leave the circle:
BGGBBGBBGBGBGGBBGGGB
Explanation / Answer
import java.util.*;
public class CircularA
{
public String[] array={"B","G","G","B","B","G","B",
"B","G","B","G",
"B","G","G","B","B","G","G","G","B"};
ArrayList<String> students=new ArrayList(Arrays.asList(array));
List<String> blue;//=new ArrayList(10);
List<String> red;//=new ArrayList(10);
int count=0,c=20;
public CircularA()
{
blue=new ArrayList(10);
red=new ArrayList(10);
}
public void arrangeStudents()
{
while(count<10)
{
for(int i=0; i<students.size();i++)
{
if(i==i*4)
{
blue.add(students.get(i));
students.remove(i);
count++;
}
}
}
for(int j=0;j<students.size();j++)
{
red.add(students.get(j));
}
}
public void printStudents()
{
System.out.println("Students in the Blue team are: "+
blue);
System.out.println("Students in the Red team are:
"+red);
}
}
import java.util.*;
public class CircularArrangement
{
public static void main(String args[])
{
CircularA ca=new CircularA();
ca.arrangeStudents();
ca.printStudents();
}
}
---------------------------------------------------------------------------------------------------------------------------------------
Sample output:
Students in the Blue team are: [B, G, G, B, B, G, B, B, G, B]
Students in the Red team are: [G, B, G, G, B, B, G, G, G, B]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.