Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class fitnessExperiment {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- //inputs
- double distance[] = {30.6, 56.8, 29.0, 105.1, 78.5, 201.1, 88.9, 99.6, 75.4, 219.2, 61.0, 59.8, 99.9, 160.0, 39.8};
- String day[] = {"1st May", "2nd May", "3rd May", "4th May", "5th May", "6th May", "7th May", "8th May", "9th May", "10th May", "11th May", "12th May", "13th May", "14th May", "15th May"};
- double temp1;
- String temp2;
- System.out.println("My longest rate, what is? And I'll classify the distances in a descending order");
- //the highest rate
- for(int i=0; i<distance.length; i++)
- {
- for(int j=1; j<(distance.length-i); j++)
- {
- if(distance[j-1]<distance[j])
- {
- temp1 = distance[j-1];
- distance[j-1] = distance[j];
- distance[j] = temp1;
- temp2 = day[j-1];
- day[j-1] = day[j];
- day[j] = temp2;
- }
- }
- }
- for(int i=0; i<distance.length; i++)
- System.out.println("My longest distance was " + distance[i] + " m, " + day[i]);
- //the average rate
- double total = 0;
- double average = 0;
- System.out.println("What was my average distance ran?");
- for(int i=0; i<distance.length; i++)
- {
- total = total + distance[i];
- average = total/15;
- }
- System.out.println("My average distance was " + average + " m");
- } //class ends
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement