Menu
Topics Index
...
`

Calculate Train Length


If you need explanation Read this topic

If you need Answer Take test on this topic

Calculate Train Length
What will be the output of the following program?
public class TrainLength {

    public static void main(String[] args) {
        double platformCrossingTimeInSecs = 100.0;
        double poleCrossingTimeInSecs = 50.0f;
        double platformLengthInMeters = 200;
        double trainLength = platformLengthInMeters * poleCrossingTimeInSecs / platformCrossingTimeInSecs - poleCrossingTimeInSecs;
        System.out.printf("Train Length In Meters = %2.2f", trainLength);
    }
}

A. Train Length In Meters = 50.00
B. Train Length In Meters = 200
C. Train Length In Meters = 200.00
D. Some other output or Compilation Error
Topic: Java Formatting Numbers

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.

A is the answer as 200*50/100-50 gives 50.0..basing on prcidncy..

Posted by Shabaaz Shaikz    2013-10-07 08:14:10


Answer is A, as in C language or printf method .nf indicates n -> number of digits to be displayed after (.)
in example 50.0 value is displayed 2 digits after  .
i.e. 50.00
if it is "2.3f" then it would display 50.000

Posted by Jayachandra Gupta    2013-10-07 08:15:15


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

Posted by Merit Campus    2013-10-10 05:26:59


Got it.. :-)

Posted by Shabaaz Shaikz    2013-10-10 09:13:47


© meritcampus 2019

All Rights Reserved.

Open In App