Vím, že mám chybu někde již v podmínkách, ale navíc mi to hází chybu i u hlavní metody. Poradil byste někdo ? Děkuji
► Zobrazit spoiler
Kód: Vybrat vše
package b13Nahodnyden;
import java.util.Random;
public class b13Nahodnyden {
public static void main(String[] args) {
Random random = new Random();
int x = random.nextInt(7) + 1;
if (x == 1) {
System.out.println("Pondělí");
}
else if (x == 2) {
System.out.println("Utery");
}
else if (x == 3) {
System.out.println("Streda");
}
else if (x == 4) {
System.out.println("Ctvrtek");
}
else if (x == 5) {
System.out.println("Patek");
}
else if (x == 6) {
System.out.println("Sobota");
}
else if (x == 7) {
System.out.println("Nedele");
}
}
}
Kód: Vybrat vše
package b13Nahodnyden;
import java.util.Random;
public class b13Nahodnyden {
public static void main(String[] args) {
Random random = new Random();
int x = random.nextInt(7) + 1;
switch(x) {
case 1:
System.out.println("Pondělí");
break;
case 2:
System.out.println("Utery");
break;
case 3:
System.out.println("Streda");
break;
case 4:
System.out.println("Ctvrtek");
break;
case 5:
System.out.println("Patek");
break;
case 6:
System.out.println("Sobota");
break;
case 7:
System.out.println("Nedele");
break;
default:
System.out.printIn("Tento den neznam");
break;
}
}
}
Kód: Vybrat vše
package b13Nahodnyden;
import java.util.Random;
public class b13Nahodnyden {
public static void main(String[] args) {
Random random = new Random();
int x = random.nextInt(7) + 1;
String[] dny = {"Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek", "Sobota", "Neděle"};
if(x > 0 && x <= 7) {
System.out.printIn(dny[x-1]);
} else {
System.out.printIn("Tento den neznam");
}
}
}
Zpět na “Programování a tvorba webu”
Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 4 hosti