package com.m;
/*某一实验,共在教室里安放200盏灯,并由1-200号同学分别按自己的倍数去开,关灯,问:200名同学依次按完后,有几盏灯开着?
* (提示:比如1号按1到200号灯,2号按2,4,6,8...200号灯,先前室内灯都是关的)*/
public class SwitchProblem {
public static void main(String args[]) {
int n=200;
int count=0;
System.out.print("The opened lights are:");
for(int i=1;i<=n;i++){
boolean bSwitch=false;
for(int j=1;j<=i;j++){
if(i%j==0){
bSwitch=!bSwitch;
}
}
if(bSwitch){
System.out.print(""+i+" ");
count++;
}
}
System.out.println("\nThe number of the opened lights:"+count);
}
}
/*某一实验,共在教室里安放200盏灯,并由1-200号同学分别按自己的倍数去开,关灯,问:200名同学依次按完后,有几盏灯开着?
* (提示:比如1号按1到200号灯,2号按2,4,6,8...200号灯,先前室内灯都是关的)*/
public class SwitchProblem {
public static void main(String args[]) {
int n=200;
int count=0;
System.out.print("The opened lights are:");
for(int i=1;i<=n;i++){
boolean bSwitch=false;
for(int j=1;j<=i;j++){
if(i%j==0){
bSwitch=!bSwitch;
}
}
if(bSwitch){
System.out.print(""+i+" ");
count++;
}
}
System.out.println("\nThe number of the opened lights:"+count);
}
}