saving . . . saved Ternary Operators has been deleted. Ternary Operators has been hidden .
Ternary Operators
Title
Question
Can you please give the solution for the question number 2 of assignment as I am unable to figure out the result/condition statement?

Java Nested-if 07-08 min 20-30 sec 20-04-21, 6:29 p.m. harshii26

Answers:

/* The program to find the largest number using Ternary Operators */

public class LargestNumber {

public static void main(String args[]) {

    int num1, num2, largestnum;
    
    num1= 10;
    num2= 60;
    
    if(num1!=num2) {
     largestnum= num1>num2?num1:num2;
     System.out.println("The Largest number is " + largestnum);
    }
    else {
    System.out.println("Both numbers are equal");
    }
    
}
}
16-07-21, 1:16 p.m. pankajap@cse.iitb.ac.in


public class LarNum {

public static void main(String args[]) {

    int a, b, larnum;
    
    a= 10;
    b= 60;
    
    if(a!=b) {
     larnum= a>b?a:b;
     System.out.println("The Largest number is " + larnum);
    }
    else {
    System.out.println("Both numbers are equal");
    }
    
}
}
06-12-21, 9:16 p.m. Harish1605


Log-in to answer to this question.