package com.codegym.task.task04.task0416;
/*
Crossing the road blindly
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
double t = Double.parseDouble(br.readLine());
double light = t%5;
if (t<=7.59){
if (t>=0&&t<=2.59){
System.out.println("green");
} else if (t>=3.0&&t<=3.59){
System.out.println("yellow");
} else if(t>=4.0&&t<=4.59){
System.out.println("red");
}
} else if (light>=3.0&&light<=3.59){
System.out.println("yellow");
} else if (light>=4.0&&light<=4.59){
System.out.println("yellow");
} else {
System.out.println("green");
}
}
}
monipuff
Level 22
requirements not met?
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Agent Smith
8 August 2020, 17:05
Try to carefully analyze what you are trying to achieve with your conditionals.
1) What is the possible range of results for a t % 5 where t is a double? Try substituting different t values, for example t < 5 and t > 5 to see what happens.
2) Can you somehow map that range to your program specification (green/yellow/red)?
In short, your conditionals look over complicated. For example, what is 7.59? Is it necessary to use here at all?
You can make the conditional part of this task with just 3 lines of code. Here is a hint how it looks:
+1