Created
January 17, 2020 14:11
-
-
Save mamiwinsfall93/1c80656ae5385feec92f2241ab9b0921 to your computer and use it in GitHub Desktop.
Crossing the road blindly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The pedestrian traffic light is programmed as follows: | |
at the beginning of each hour, the green signal is on for three minutes, | |
then the signal is yellow for one minute, | |
and then it is red for one minute. | |
Then the light is green again for three minutes, etc. | |
Use the keyboard to enter a real number t that represents the number of minutes that have elapsed since the beginning of the hour. | |
Determine what color the traffic light is at the specified time. | |
*/ | |
import java.io.*; | |
public class Solution { | |
public static void main(String[] args) throws Exception { | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
double n = Double.valueOf(reader.readLine()); | |
double roundN = Math.floor(n); | |
double lightTime = roundN % 5; | |
if (lightTime>=0 &&lightTime<3){ | |
System.out.println("green"); | |
}else if (lightTime>=3 && lightTime<4){ | |
System.out.println("yellow"); | |
}else { | |
System.out.println("red"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment