Menu
Topics Index
...
`

Arithmetic Operators And ifelseif


If you need explanation Read this topic

If you need Answer Take test on this topic

Arithmetic Operators And ifelseif
What will be the output of the following program?
public class Numeric
{
    public static void main(String args[])
    {
        mystery(-99);
    }
    public static void mystery(int n)
    {
        if(n > 10)
        {
            n = n / 2;
        }
        else
        {
            n = n + 7;
        }
        if (n * 2 < 25)
        {
            n = n + 10;
        }
        System.out.println(n);
    }
}

A. 99
B. -82
C. 55
D. 111
E. Compilation Error or Runtime Error
Topic: Java Methods - Parameter Passing And Scope

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is B here we have the mystery method in that we are check if it is greater than the 10 than we are dividing it by 2 but -99 < 100 so we are adding 7 to it than it will become -92 next we are checking -184<25 it is true so we are adding 10 to it than it will become -82

Posted by Uday Kumar    2015-03-11 08:41:52


Ans is B  here execution starts with main() here mystery method is called and in mystery method parameter -99 is passed of type int here in the if condition is checked -99 is not greater than 10 condition failed and in else n= -99+7 =-92  and then again if  condition  is checked here -99×2<25  here n=n+10 ie n=-92+10=-82 and it prints -82

Posted by Ramya Reddy Addulla    2015-03-11 09:06:54


-82

Posted by Sunny Sravani    2015-03-11 10:51:39


B: -82

Posted by Sandeep Reddy    2015-03-11 15:04:38


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar, Ramya Reddy Addulla,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Ammad Islam. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-03-12 02:02:45


© meritcampus 2019

All Rights Reserved.

Open In App