Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int steps = Integer.parseInt(sc.nextLine());
- double stepLength = Double.parseDouble(sc.nextLine());
- int distance = Integer.parseInt(sc.nextLine());
- double totalDistance = 0;
- double tempStep = stepLength;
- for (int i = 1; i <= steps; i++) {
- if (i%5==0) {
- stepLength = stepLength * 0.7;
- }
- totalDistance += stepLength;
- stepLength = tempStep;
- }
- System.out.printf("You travelled %.2f%% of the distance!", (totalDistance * 100) / (distance * 100));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement