Hi there, so I\'m writting a java program that adds and subtracts two really big
ID: 3543911 • Letter: H
Question
Hi there, so I'm writting a java program that adds and subtracts two really big numbers that are being stored in ArrayList. Therefore, I have a boolean method called getBigger() that returns true if the fisrt number in the argument of parameters is bigger that the second:
example:
public boolean getBigger(ArrayList<Integer> number1, ArrayList<Integer> number2){
// it returns true if "number1" is bigger than "numer2"
I could do this by checking its size, howeve lets say that:
the number beign passed in number1 is: 22444444555663
the number being passed in number2 is: 22111111111223
how could I check for the biggest one if the size is the same?
Please help!
Explanation / Answer
public boolean getBigger(ArrayList<Integer> number1, ArrayList<Integer> number2)
{
if(number1.size() > number2.size())
return true;
else if(number1.size() < number2.size())
return false;
else
{
int a,b,temp;
Iterator itr1 = number1.iterator();
Iterator itr2 = number2.iterator();
while(itr1.hasNext())
{
a = (itr1.next()).intValue();
b = (itr2.next()).intValue();
if(a>b)
return true;
else if(b>a)
return false;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.