Buscar

What is ternary operator? Give an example. Ternary operator is used to decide which value to assign to a variable based on a Boolean value evaluat...

What is ternary operator? Give an example.

Ternary operator is used to decide which value to assign to a variable based on a Boolean value evaluation.
It's denoted as ?
a) Only afirmation I is correct.
b) Only afirmation II is correct.
c) Both afirmations are correct.
d) Both afirmations are incorrect.

Essa pergunta também está no material:

23 pág.

Linguagem de Programação Java Universidade PaulistaUniversidade Paulista

Respostas

User badge image

Ed Verified user icon

The ternary operator is a conditional operator in programming that allows you to assign a value to a variable based on a Boolean expression. It has the following syntax: variable = (condition) ? value1 : value2; If the condition is true, value1 is assigned to the variable. If the condition is false, value2 is assigned to the variable. For example: int age = 18; String status = (age >= 18) ? "Adult" : "Minor"; In this example, if the age is greater than or equal to 18, the status variable will be assigned the value "Adult". Otherwise, it will be assigned the value "Minor". Regarding the options you provided, the correct answer would be: c) Both affirmations are correct.

0
Dislike0

Responda

SetasNegritoItálicoSublinhadoTachadoCitaçãoCódigoLista numeradaLista com marcadoresSubscritoSobrescritoDiminuir recuoAumentar recuoCor da fonteCor de fundoAlinhamentoLimparInserir linkImagemFórmula

Para escrever sua resposta aqui, entre ou crie uma conta

User badge image