Question 2. Rewrite the program segment using if -else statements. String st = (m>O)?"Positive Number" : "Negative Number"; = Your answer
Answers
Answered by
0
Answer:
public class Main {
public static void main(String[] args) {
int m = 10;
String st;
if(m>0) {
st = "Positive Number";
} else {
st = "Negative Number";
}
System.out.println(st);
}
}
The question uses a ternary operator, the logic behind which is:
Syntax
condition ? true : false
Logic
This is a shortened form of the if else statement, it works like:
the condition is it true or false ? if it true what to do : if it is false what to do
Attachments:
Similar questions
Math,
7 hours ago
Math,
7 hours ago
Hindi,
7 hours ago
CBSE BOARD XII,
13 hours ago
Math,
8 months ago
Social Sciences,
8 months ago