10 exemplos do comando if/else ppfvvv pessoal
Soluções para a tarefa
Resposta:
Exemplos Java
1)if (20 > 18) {
System.out.println("20 is greater than 18");
}
2)int x = 20;
int y = 18;
if (x > y) {
System.out.println("x is greater than y");
}
3)int time = 20;
if (time < 18) {
System.out.println("Good day.");
} else {
System.out.println("Good evening.");
}
4)int time = 22;
if (time < 10) {
System.out.println("Good morning.");
} else if (time < 20) {
System.out.println("Good day.");
} else {
System.out.println("Good evening.");
}
5)int time = 20;
String result = (time < 18) ? "Good day." : "Good evening.";
System.out.println(result);
Exemplos Javascript
1)var time = new Date().getHours();
if (time < 20) {
document.getElementById("demo").innerHTML = "Good day";
}
2)var time = new Date().getHours();
if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
3)var time = new Date().getHours();
if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
4)var x = document.getElementsByTagName("DIV")[0];
if (x.id === "myDIV") {
x.style.fontSize = "30px";
}
5)var x, text;
x = document.getElementById("numb").value;
if (isNaN(x) || x < 1 || x > 10) {
text = "Input not valid";
} else {
text = "Input OK";
}
Explicação: Espero ter ajudado.