I have a problem with a task. I must transform the following doWhile loop into a While loop, so that the result of both loops is the same?
As you can see the type Integer
is just in the doWhile loop. But what's the difference between type int
. How do I solve this task?
doWhile loop:
public Integer a_doWhile(int x){
int i = 0;
Integer result;
do {
result = ++i*i;
} while (result < x);
return result;
}
My solution:
public Integer a_while(int x){
int i=0;
int result;
while(result < x){
result = ++i*i;
return result;
}
}
But my solution is wrong. It has to do sth with this "Integer", Can someone help me please? Thanks :)