package com.codegym.task.task04.task0416;
/*
Crossing the road blindly
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
String d = f.readLine();
double t = Double.parseDouble(d);
if (t % 5 == 0){
String light = "green";
}
else if (t % 4 == 0 && t % 4 > 2){
String light = "red";
} else if (t % 3 == 0 && t % 3 > 1.5){
String light = "yellow";
System.out.println(light);
}
}
}
i dont know what to do omg please help
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
anna
7 August 2020, 11:33
There is a simple solution: modulo five over all the possibilities!
Think what would be the "leftovers" when dividing each of the lights into 5 (the sicle of lights repeats itself every 5 minutes).. Try that:
double a=scanner.nextDouble();
if (a%5<3){
System.out.println("green"); }
else if(a%5>=4){
System.out.println("red"); }
else{
System.out.println("yellow"); }
+1
Mnemonic
3 August 2020, 11:16
Scanner input = new Scanner(System.in);
int a = (int) input.nextDouble();
if((a == 0 | a == 1 | a == 2) & a <= 60)
System.out.println("green");
else if((a % 5 == 0 | a % 5 == 1 | a % 5 == 2) & a <= 60)
System.out.println("green");
else if(a == 3 | a % 5 == 3 & a <= 60)
System.out.println("yellow");
else if((a == 4 | a % 5 == 4) & a <= 60)
System.out.println("red");
else
System.out.println("The number needs to be between 1 and 60");
0
Dyrits
2 July 2020, 08:50
Just use the modulo operator with 5 and compare the result.
You'll notice a pattern.
When the result is less than 3, it is green. When the result is less than 4 it is yellow. Otherwise, it is red.
+1
Kent
29 June 2020, 19:02
One of the problems is line 24, your output is part of the last else if statement. Move it outside of the else if statement and you should start getting some output.
0