Menu
Topics Index
...
`

Find balance


If you need explanation Read this topic

If you need Answer Take test on this topic

Find balance
What will be the output of the following program?
public class Balance {
    public static void main(String[] args) {
        float xBal = 10.0f;
        double yBal = 20.0;
        System.out.print("After loan x,y bal is ");
        System.out.print(Math.copySign(xBal, -yBal));
        System.out.print(" " + Math.copySign(-yBal, -xBal));
    }
}

A. After loan x,y bal is -10.0 -20.0
B. After loan x,y bal is -10.0 20.0
C. Compilation Error
D. Runtime Error
Topic: Java Math Class - java.lang.Math

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.

D.compilation error.as copySign (double).

Posted by Shabaaz Shaikz    2014-02-05 12:56:36


answer is B.

Posted by Gopinath Manchikanti    2014-02-05 13:46:30


A,as Math.copySign(arg1,arg2) method returns the first argument with the sign of the second argument.in the first call xbal is assigned -ybal's sign so output will be -10.0 and in the second call for -ybal , - (current sign of xbal which is -ve) is assigned so ybal gets -ve sign. so final output becomes -10.0 -20.0

Posted by Prem Mengani    2014-02-05 15:57:23


Answer is C(compilation error).The java.lang.Math.copySign(double magnitude, double sign) returns the first floating-point argument with the sign of the second floating-point argument.

Posted by Anvesh Athmakuri    2014-02-05 18:12:52


Congratulations Prem Mengani. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-02-06 04:27:11


© meritcampus 2019

All Rights Reserved.

Open In App