Questão FC373265
Considere o código Java abaixo. int a = 1, b = 2, c = 3, d = 4; boolean x, y, z; x = !(!(a < d || d / b == b) && !false); y = (b * a + a == b && b*c-d == b) || (d-b >= c && b+a+c >
Linguagens de Programação
FCC · 2022
Considere o código Java abaixo.
int a = 1, b = 2, c = 3, d = 4;
boolean x, y, z;
x = !(!(a < d || d / b == b) && !false);
y = (b * a + a == b && b*c-d == b) || (d-b >= c && b+a+c >= d);
z = !x && !y || !(d > c + 1);
Os valores que serão armazenados nas variáveis x, y e z são, correta e respectivamente,
- true − true − true.
- true − false − false.
- false − false − false.
- false − false − true.
- true − false − true.
Mostrar resposta e comentário
Gabarito
Errado
Comentário do professor
Substitua os valores \(a=1,b=2,c=3,d=4\) e respeite a precedência: parênteses, !, &&, ||.
Para x: \(x = !(!(ax = true.
Para y: \(y = (b*a+a==b && b*c-d==b) || (d-b>=c && b+a+c>=d)\) → substituindo: \((3==2 && 2==2) || (2>=3 && 6>=4)\) → \((false && true) || (false && true) = false || false = false\). Assim, y = false.
Para z: \(z = !x && !y || !(d>c+1)\) → \(!true && !false || !(4>3+1)\) → \(false && true || !(4>4)\) → \(false || !false = true\). Portanto, z = true.
Conteúdo do catálogo FC Concursos · Atualizado em