Hello,
Please check my code below. I tried many solutions, and at the end I decied to use the easiest one. There wasn't loops on the course yet, so I assume that I shouldn't use any of them here. The code gives right answers, but it doesn't "pass" the tests. Could you explain me why is that?
package pl.codegym.task.task04.task0416;
/*
Przejście przez ulicę na oślep
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//tutaj wpisz swój kod
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String liczba = reader.readLine();
double t = Double.parseDouble(liczba);
if (t >= 0 && t < 3 || t >=6 && t <8 || t>= 11 && t<13 || t>=16 && t<18 || t>=21 && t< 23 || t>=26 && t< 29 || t>=31 && t< 33 || t>= 36 && t < 38 || t>=41 && t<43 || t>=46 && t<48 || t>=51 && t< 53 || t>=56 && t<58)
{
System.out.println("zielone");
}
if (t==3 || t==8 || t==13||t==18||t==23||t==28||t==33||t==38||t==43||t==48||t==53||t==58)
{
System.out.println("pomarańczowe");
}
if (t==4 || t==9 || t==14||t==19||t==24||t==29||t==34||t==39||t==44||t==49||t==54||t==59)
{
System.out.println("czerwone");
}
}
}
package pl.codegym.task.task04.task0416;
/*
Przejście przez ulicę na oślep
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//tutaj wpisz swój kod
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String liczba = reader.readLine();
double t = Double.parseDouble(liczba);
if (t >= 0 && t < 3 || t >=6 && t <8 || t>= 11 && t<13 || t>=16 && t<18 || t>=21 && t< 23 || t>=26 && t< 29 || t>=31 && t< 33 || t>= 36 && t < 38 || t>=41 && t<43 || t>=46 && t<48 || t>=51 && t< 53 || t>=56 && t<58)
{
System.out.println("zielone"); //green
// System.exit(0);
}
if (t==3 || t==8 || t==13||t==18||t==23||t==28||t==33||t==38||t==43||t==48||t==53||t==58)
{
System.out.println("pomarańczowe"); //yellow
//System.exit(0);
}
if (t==4 || t==9 || t==14||t==19||t==24||t==29||t==34||t==39||t==44||t==49||t==54||t==59)
{
System.out.println("czerwone"); //yellow
//System.exit(0);
}
/*if (t==5 || t==10 || t==15||t==20||t==25||t==30||t==35||t==40||t==45||t==50||t==55||t==60)
{
System.out.println("czerwone"); //red
//System.exit(0);
}*/
}
}