Rewrite the following condition without using logical operator:-
If(a>b||a>c)
System.out.println(a);
Answers
Answered by
134
Answer:
import java.until.*;
class Xy
{
public static void main(String args[])
{
int a,b;
if(a>b)
System. out.println(a);
if(a>c)
System. out.println(a);
}
}
Answered by
10
condition without using logical operator:-
instead of using the logical operator, we can use the ternary operator in its place in this case.
ternary operator :
a>b ? True : False -- if the condition is true the the true value is printed and if the condition is false then the false value is printed.
By simply making the changes below:
System.out.println( (a>b)? (a>c ? a:c) : ((b>c) ? b:c ));
Similar questions
Computer Science,
5 months ago
Math,
5 months ago
English,
5 months ago
Hindi,
10 months ago
English,
10 months ago
Social Sciences,
1 year ago
Chemistry,
1 year ago