Only green color is not displayed. Please guide.
package com.codegym.task.task04.task0416;
/*
Crossing the road blindly
Crossing the road blindly
Let's say that we are certain that at the beginning of every hour
ur traffic light is green for 3 minutes, yellow for a minute, and
en red for another minute. Then the sequence repeats. Our program
must determine what light is on now (where "now" is a real number that indicates
the number of minutes that have elapsed since the beginning of the hour).
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.
Display the result as follows:
"green" if the light is green,
"yellow" if the light is yellow, and
"red" if the light is red.
Example for 2.5:
green
Example for 3:
yellow
Example for 4:
red
Example for 5:
green
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
float time;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
time = Float.parseFloat(br.readLine());
if(time>5)
time=time%5;
if(time <3)
System.out.println("green");
else if(time <4)
System.out.println("yellow");
else if(time <5)
System.out.println("red");
}
}