Pavan Putra Boy - 1 year ago 61

Java Question

I am not very good in maths . So please don't mind my mistakes !

This is the question :

Speedy kings are a racing group. Their leader John owns a Suzuki

Hayabusa which has a maximum speed of 300 kmph. The leader of the

rival group, Ranson owns a Ducati whose maximum speed is 280 kmph.

John makes n rounds of 10km track. How much time(in minutes) will

Ranson take to complete the same distance covered by John. Take the

value of n as input from the user. Sample Input: 4 Sample Output: 8

Now this is my solution :

`class speedyKings{`

public static void main(String args[]){

Scanner in=new Scanner(System.in);

int ducs=280;

int hays=300;

int total_dist=10000;

int n=in.nextInt();

double time=((10000*n)/280);

System.out.print(time);

}

}

But it is not giving the right output can anybody help ?

Answer Source

Your best bet is to take *small* steps to get to the right value. You can use appropriately named variables to remember what you're looking at and working with:

```
Scanner in = new Scanner(System.in);
int laps = in.nextInt();
double speedInKph = 280; // km/h
double lapLength = 10000; // meter
double speedInMpS = speedInKph * 1000 / 3600; // m/s
double secondsPerLap = lapLength / speedInMpS; // m / (m/s) = s
double minutesPerLap = secondsPerLap / 60;
double minutes = minutesPerLap * laps;
System.out.println("Minutes: " + minutes);
```