package pl.codegym.task.task04.task0416;
/*
Przejście przez ulicę na oślep
*/
import java.io.*;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
double minute = scanner.nextDouble();
while(minute>=5){
minute-=5;
}
while(minute<5) {
if (minute >= 0 && minute < 3) {
System.out.println("zielone"); //green
System.exit(0);
}
if (minute >= 3 && minute < 4) {
System.out.println("żółte"); //yellow
System.exit(0);
}
if (minute >= 4 && minute < 5) {
System.out.println("czerwone"); //red
System.exit(0);
}
}
}
}
It works on IntelliJ but it fails on website
Rozwiązane
Komentarze (4)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
kochansky
2 stycznia 2020, 09:36
You need print "pomaranczowy" instead of "zolty"
and use break; instead of System.exit(0);
0
Krzysztof
2 grudnia 2019, 16:10
there is a problem with line 20, 24, 28. I think codegym extension doesnt recognize this command or something, I need to replace it but I dont know which command may I use to exit the program. Any suggestions?
+1
Ivan
2 grudnia 2019, 17:06przydatny
Firstly, delete those lines, 20, 24 and 28.
Secondly, you don't need while loop. You need the entered number to be mod (%) and have that result in your ifs.
double result (e.g.) = minute % 5 (5 is the cycle); now have the results substitute minute in your ifs, and you are ready.
+1
Ala
3 grudnia 2019, 06:54
...and addictionally replace "żółty" by "pomarańczowy" ;)
+2