Unit 7 Array List Homework
import java.util.*;
import java.lang.Math;
ArrayList<Integer> number = new ArrayList<Integer>();
ArrayList<Integer> number2 = new ArrayList<Integer>();
for (int i = 0; i < 5; i++){
number.add(i);
}
for (int i = 5; i > 0; i--){
number.add(i);
}
System.out.println("Original: " +number);
System.out.println("HashCode: " + number.hashCode());
number.sort(Comparator.reverseOrder());
System.out.println("ArrayList after sort: " + number);
System.out.println("HashCode: " + number.hashCode());
Collections.swap(number, 4, 0);
System.out.println("Swap the first and last elements: " + number);
System.out.println("HashCode: " + number.hashCode());
boolean a;
boolean b;
for (int i=0; i < number.size() - 1; i++){
if (!(number.get(i) <= number.get(i + 1))){
boolean a = false;
}
if (!(number.get(i) >= number.get(i + 1))){
boolean b = false;
}
}
if (a){
System.out.println("ascending");
}
if (b){
System.out.println("descending");
}
else{
System.out.println("neither");
}