Computer Applications
The driver took a drive to a town 240 km at a speed of 60 km/h. Later in the evening, he drove back at 20 km/h less than the usual speed. Write a program to calculate:
- the total time taken by the driver
- the average speed during the whole journey
[Hint: average speed = total distance / total time]
Java
Input in Java
53 Likes
Answer
public class KboatJourney
{
public static void main(String args[]) {
int distance = 240;
float speed = 60.0f;
float returnSpeed = speed - 20;
float time2Reach = distance / speed;
float time2Return = distance / returnSpeed;
float totalTime = time2Reach + time2Return;
float avgSpeed = (distance * 2) / totalTime;
System.out.println("Total time: " + totalTime);
System.out.println("Average speed: " + avgSpeed);
}
}
Variable Description Table
Program Explanation
Output
Answered By
24 Likes
Related Questions
Write a program to input time in seconds. Display the time after converting them into hours, minutes and seconds.
Sample Input: Time in seconds: 5420
Sample Output: 1 Hour 30 Minutes 20 Seconds
A man spends (1/2) of his salary on food, (1/15) on rent, (1/10) on miscellaneous activities. Rest of the salary is his saving. Write a program to calculate and display the following:
- money spent on food
- money spent on rent
- money spent on miscellaneous activities
- money saved
Take the salary as an input.
Write a program to input two unequal numbers. Display the numbers after swapping their values in the variables without using a third variable.
Sample Input: a = 76, b = 65
Sample Output: a = 65, b = 76
A certain amount of money is invested for 3 years at the rate of 6%, 8% and 10% per annum compounded annually. Write a program to calculate:
- the amount after 3 years.
- the compound interest after 3 years.
Accept certain amount of money (Principal) as an input.
Hint: A = P * (1 + (R1 / 100))T * (1 + (R2 / 100))T * (1 + (R3 / 100))T and CI = A - P