answersLogoWhite

0


Best Answer

// largest = largest of a, b, c

public class largest

{

public static void main(String args[])

{

int a,b,c,largest;

a=0;

b=0;

c=0;

a=Integer.parseInt(args[0]);

b=Integer.parseInt(args[1]);

c=Integer.parseInt(args[2]);

largest=a>b?(a>c?a:c):(b>c?b:c);

System.out.println("The largest no. of "+a+","+b+"and"+c+"is"+largest);

}

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

// Returns the largest value out of (a,b,c)

int getLargest(final int a, final int b, final int c) {

// Maximum of a and b

int ab = a>b?a:b;


// Maximum of ab and c
int max = ab>c?ab:c;

return max;

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Initially assume the maximum is equal to the first number. Then compare the maximum to the second number; if the second number is larger than the temporary maximum, assign the second number to the maximum. Repeat for the third number.

If you use a for loop, and an array, you can easily expand the program to get the largest out of much larger sets of numbers.

Initially assume the maximum is equal to the first number. Then compare the maximum to the second number; if the second number is larger than the temporary maximum, assign the second number to the maximum. Repeat for the third number.

If you use a for loop, and an array, you can easily expand the program to get the largest out of much larger sets of numbers.

Initially assume the maximum is equal to the first number. Then compare the maximum to the second number; if the second number is larger than the temporary maximum, assign the second number to the maximum. Repeat for the third number.

If you use a for loop, and an array, you can easily expand the program to get the largest out of much larger sets of numbers.

Initially assume the maximum is equal to the first number. Then compare the maximum to the second number; if the second number is larger than the temporary maximum, assign the second number to the maximum. Repeat for the third number.

If you use a for loop, and an array, you can easily expand the program to get the largest out of much larger sets of numbers.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

It seems quite complicated - and confusing - to try to do this using only the ternary operator. I suggest you use any method to sort the three numbers using an array (bubble sort should be appropriate, since there are only a few numbers), then take the second number. Note that this method can easily be extended to finding the largest, second-largest, third-largest, etc. number, from among a set of any size.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Initially assume the maximum is equal to the first number. Then compare the maximum to the second number; if the second number is larger than the temporary maximum, assign the second number to the maximum. Repeat for the third number.

If you use a for loop, and an array, you can easily expand the program to get the largest out of much larger sets of numbers.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Biggest of three numbers using ternary operator in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you find the greatest of three numbers using ternery operator?

Compare the first two numbers with the ternary operator. Store the result in a temporary variable. Compare the temporary variable with the third number, again using the ternary operator.


What is the conditional operators in c language?

The conditional operator is also known as ternary operator. It is called ternary operator because it takes three arguments. The conditional operator evaluates an expression returning a value if that expression is true and different one if the expression is evaluated as false.Syntax:condition ? result1 : result2If the condition is true, result1 is returned else result2 is returned.


Which operator is called ternary operator?

A ternary operator is an operator that requires three operands, as opposed to a binary operator that requires two operands and a unary operator that requires just one operand. C++ has just one ternary operator, the conditional ternary operator: <boolean expression> ? <expression #1> : <expression #2>; If the boolean expression evaluates true, the first expression is evaluated, otherwise the second expression is evaluated. A typical usage of this operator is to return the larger (or smaller) of two values of type T: template<typename T> T max (T a, T b) {return a<b ? b : a}; template<typename T> T min (T a, T b) {return a<b ? a : b}; These are really nothing more than notational shorthand for the following: template<typename T> T max (T a, T b) {if (a<b) return b; else return a; }; template<typename T> T min (T a, T b) {if (a<b) return a; else return b;}; However, because ternary expressions are evaluated, the return value of the expression can be used in more complex expressions: int a=42, b=0; // ... int c = ((a>b ? a : b) = 1); In the above expression, whichever is the larger of a and b will be assigned the value 1 which will also be assigned to c. Thus a and c become 1 while b remains 0.


What is conditional expression operator?

The conditional operator (? :) is a ternary operator (it takes three operands). The conditional operator works as follows:The first operand is implicitly converted to bool. It is evaluated and all side effects are completed before continuing.If the first operand evaluates to true (1), the second operand is evaluated.If the first operand evaluates to false (0), the third operand is evaluated.The result of the conditional operator is the result of whichever operand is evaluated - the second or the third. Only one of the last two operands is evaluated in a conditional expression.


Draw a flow chart to find out the greatest number among the three given numbers ab c?

draw a flowchart to find the biggest number among the 3 numbers

Related questions

How do you find the greatest of three numbers using ternery operator?

Compare the first two numbers with the ternary operator. Store the result in a temporary variable. Compare the temporary variable with the third number, again using the ternary operator.


C program to find the largest among three numbers using ternary operator?

max = a > b ? a : b; max = max > c ? max : c;


What is the conditional operators in c language?

The conditional operator is also known as ternary operator. It is called ternary operator because it takes three arguments. The conditional operator evaluates an expression returning a value if that expression is true and different one if the expression is evaluated as false.Syntax:condition ? result1 : result2If the condition is true, result1 is returned else result2 is returned.


What does ternary ionic compound mean?

"Ternary" means that the compound contains three elements.


Enumerate the IUPAC rules in naming ternary compounds?

ternary compuonds are composed of three elements


How to make decision making statements in c plus plus?

Decision making statements make use of conditional expressions. In C++ there are three possibilities: if/else, switch/case and the ternary operator (?:).


Which operator is called ternary operator?

A ternary operator is an operator that requires three operands, as opposed to a binary operator that requires two operands and a unary operator that requires just one operand. C++ has just one ternary operator, the conditional ternary operator: <boolean expression> ? <expression #1> : <expression #2>; If the boolean expression evaluates true, the first expression is evaluated, otherwise the second expression is evaluated. A typical usage of this operator is to return the larger (or smaller) of two values of type T: template<typename T> T max (T a, T b) {return a<b ? b : a}; template<typename T> T min (T a, T b) {return a<b ? a : b}; These are really nothing more than notational shorthand for the following: template<typename T> T max (T a, T b) {if (a<b) return b; else return a; }; template<typename T> T min (T a, T b) {if (a<b) return a; else return b;}; However, because ternary expressions are evaluated, the return value of the expression can be used in more complex expressions: int a=42, b=0; // ... int c = ((a>b ? a : b) = 1); In the above expression, whichever is the larger of a and b will be assigned the value 1 which will also be assigned to c. Thus a and c become 1 while b remains 0.


Acids that have three or more elements?

Sulfuric acid, Sulfurous acid, Nitric acid


What is 17.81 0.45 5.73?

Three numbers, not related to one another by any mathematical operator.


Where can someone find out the definition of ternary?

The definition of ternary can be found at websites, such as The Free Dictionary, Merriam-Webster and Oxford Dictionaries. Ternary is a term that is used to describe the groups consisting of three members or components.


What is the difference between rondo and ternary?

Ternary is a object consisting of three items. A rondo is a more specific term; it is a work or movement in music that is stated at least three times in the same key.


What is 1 and 6 and 11?

That's a list of three numbers. If you actually mean 'and' like in the Boolean operator and you write the numbers as binaries, then the result is zero.