I am given a problem in which I have to store a list of N numbers in an array and then sort it ,
and then I have to add the numbers at alternative positions and output the sum.
The problem is the constraint of N i.e 0 <= N <= 1011 so I have to declare the N as double type variable here is my code :
ArrayList<Double> myList = new ArrayList<Double>();
myList.add(number);
.....
Collections.sort(myList);
String tempNo = "";
for(double i = 0 ; i < myList.size() ; i=i+2){
tempNo = myStringWayToAdd(tempNo , myList(i)+""); // Since the sum will exceed the limit of double I have to add the numbers by help of Strings
}
But the problem is that the get(int)
method takes an int
not double
. Is there any other way I can solve the problem? , and Is it even allowed to store number of elements that exceed int
range?
Any help will be highly appreciated. Thank you in Advance.
Edit 1 : I can use Strings instead of
double
in ArrayList
and then add up the numbers but my problem is that i need to store N elements which can exceed the range of Integers