Computer Applications
Using the ternary operator, create a program to find the largest of three numbers.
Java
Java Conditional Stmts
13 Likes
Answer
import java.util.Scanner;
public class KboatLargestNumber
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter first number: ");
int a = in.nextInt();
System.out.print("Enter second number: ");
int b = in.nextInt();
System.out.print("Enter third number: ");
int c = in.nextInt();
int max = a > b ? a : b;
max = max > c ? max : c;
System.out.print("Largest Number = " + max);
}
}
Output
Answered By
6 Likes
Related Questions
Write a program in Java to read three integers and display them in descending order.
Admission in a professional course is subject to the following criteria:
- Marks in Physics >= 70
- Marks in Chemistry >= 60
- Marks in Mathematics >= 70
- Total marks in all subjects >= 225
Or
Total marks in Physics and Mathematics >= 150
Write a program in Java to accept marks in these 3 subjects (Physics, Chemistry, and Mathematics) and display if a candidate is eligible.
Write a program in Java that reads a word and checks whether it begins with a vowel or not.
Write a program that reads a month number and displays it in words.