Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class donations {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int donations[] = {20, 15, 36, 31, 40, 45, 30, 100, 70, 50};
- String names[] = {"Dina", "Charlie", "Charlize", "Roy", "Finn", "Olivia", "Amy", "James", "Annie", "Leo"};
- int topDonation;
- int temp1;
- String temp2;
- for(int i=0; i<donations.length; i++)
- {
- topDonation = i; //the highest amount of donations
- for(int j=i+1; j<donations.length; j++)
- {
- if(donations[topDonation]<donations[j])
- topDonation = j;
- }//end of inner loop
- if(topDonation != i)
- {
- temp1 = donations[i];
- donations[i] = donations[topDonation];
- donations[topDonation] = temp1;
- temp2 = names[i];
- names[i] = names[topDonation];
- names[topDonation] = temp2;
- }
- }
- for(int i=0; i<donations.length; i++)
- System.out.println(donations[i] + " DKK donated by " + names[i]);
- }//class ends
- }//program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement