#Array List Help
1 messages · Page 1 of 1 (latest)
Hey, @stuck sphinx!
Please remember to /close this post once your question has been answered!
- Declare an ArrayList of Double and call constructor to create the ArrayList
- Prompts the user to enter 5 numbers, stores them in the ArrayList
- Display the contents of the list by invoking the toString() method. System.out.println(list);
- Invoke the built in sort method. java.util.Collections.sort.
- Display the list. (It should be sorted in increasing order. _
- Use java.util.Collections.shuffle(list); to rearrange the list
- Print out the shuffled list -- write a loop for this, rather than using the toString() method. Have the loop condition check when to stop by using size() method, rather than hard coding a number.
- Display the minimum and largest value in the list by using the min and max methods.
this is what I need to do
import java.util.List;
import java.util.Scanner;
public class ArrayList {
//NEED TO FIGURE OUT PROPER ARRAY LIST and how to sort properly
public static void main(String[] args) {
List<Double> list = new java.util.ArrayList<>();
Scanner input = new Scanner(System.in);
System.out.println("Please Enter 5 Numbers");
for (int i=0; i<5; i++){
System.out.println("Please enter "+i+ " number");
list.add(input.nextDouble());
}
System.out.println(list.toString());
}
}
this is my code, unsure how to properly set up an arraylist
We're not just gonna do your homework for you; what specifically are you having trouble with? It looks like your code will work
I'm not asking for homework to be done
I'm showing like what I am trying to accomplish and I dont know how to really declare an array list of double
thats where I am stuck
thats an array list?
am I sorting wrong then?
oh
uh
I could be mentally handicap
I copy and pasted my arrayList is there any better way to do it
I think you should just read the javadoc for List or ArrayList, it explains everything