one line conditional statement in c
str = arraeck(a, n) ? "YES" : "NO";
printf(arraeck(a, n) ? "YES" : "NO");
one line conditional statement in c
str = arraeck(a, n) ? "YES" : "NO";
printf(arraeck(a, n) ? "YES" : "NO");
ternary operator
// (condition) ? (if true, do this) : (otherwise, do this)
const hasAccount = true
// let userDisplayMessage
// if (hasAccount) {
// userDisplayMessage = 'Welcome Back'
// } else {
// userDisplayMessage = 'Please Sign Up'
// }
const userDisplayMessage = hasAccount ? 'Welcome Back' : 'Please Sign Up'
console.log(userDisplayMessage)
ternary operator
// It is bascially an if else statement but is an operator
// Heres a program to get the largest of 3 numbers
import java.util.Scanner;
public class Program_19{
static void main(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number 1 [int]: ");
int num1 = sc.nextInt();
System.out.println("Enter Number 2 [int]: ");
int num2 = sc.nextInt();
System.out.println("Enter Number 3 [int]: ");
int num3 = sc.nextInt();
int largest = (num1>num2)? ((num1>num3)?num1:num3) : ((num2>num3)? num2:num3);
System.out.println(largest+" is the largest among the 3 numbers");
}
}
ternary operator
// syntax:
condition ? console.log("true") : console.log("false");
// e.g:
let n = 15;
n % 2 === 0 ? console.log("even number") : console.log("odd number");
How does ternary operator works ?
let moneyAmount = 80;
let creditCardAmont = 70;
let drink = (moneyAmount > 60 && creditCardAmont > 50) ? 'buy coke' : 'filter water';
console.log(drink)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us