Advertisement
meteor4o

JF-MidExam-30June-Group1-01.DistanceCalculator

Jul 2nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6.  
  7. int steps = Integer.parseInt(sc.nextLine());
  8. double stepLength = Double.parseDouble(sc.nextLine());
  9. int distance = Integer.parseInt(sc.nextLine());
  10. double totalDistance = 0;
  11. double tempStep = stepLength;
  12.  
  13.   for (int i = 1; i <= steps; i++) {
  14.    
  15.     if  (i%5==0) {
  16.       stepLength = stepLength * 0.7;
  17.     }
  18.   totalDistance += stepLength;
  19.   stepLength = tempStep;
  20.   }
  21. System.out.printf("You travelled %.2f%% of the distance!", (totalDistance * 100) / (distance * 100));
  22.  
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement