Unit 7 Application
import java.util.ArrayList;
import java.util.Collections;
ArrayList<Integer> numbers = new ArrayList<>(Arrays.asList(1,2,3,4,20,30,101,72,23,31,90,66));
Collections.sort(numbers);
Collections.reverse(numbers);
System.out.println("in decending order: " + numbers);
public static void swap_firstANDlast(){
Integer temp = numbers.get(0);
int last_index = numbers.size()-1;
numbers.set(0, numbers.get(last_index));
numbers.set(last_index, temp);
System.out.println("first and last element flipped while decending: " + numbers);
}
swap_firstANDlast()
import java.util.ArrayList;
import java.util.Collections;
ArrayList<Integer> numbers2 = new ArrayList<>(Arrays.asList(1,2,3,4,20,30,101,72,23,31,90,66));
public void status(ArrayList<Integer> list){
ArrayList<Integer> numbers_acending = (ArrayList<Integer>)numbers2.clone();
Collections.sort(numbers_acending);
System.out.println(numbers_acending);
ArrayList<Integer> numbers_decending = (ArrayList<Integer>)numbers_acending.clone();
Collections.reverse(numbers_decending);
System.out.println(numbers_decending);
if (numbers_acending == numbers2){
System.out.println("acending");
}
else if (numbers_decending == numbers2){
System.out.println("decending");
}
else{
System.out.println("neither");
}
}
//System.out.print(numbers_decending);
System.out.println(numbers2);
status(numbers2);