Computer Science, asked by guidaakfh, 13 hours ago

Question 2. Rewrite the program segment using if -else statements. String st = (m>O)?"Positive Number" : "Negative Number"; = Your answer​

Answers

Answered by SpandanMukherjee428
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