# Thread: Understanding Problem in Code !

1. Member
Join Date
Nov 2011
Posts
77
Rep Power
0

## Understanding Problem in Code !

Consider the following code:

Java Code:
```public class Aufg3 {
public static void main(String[] args) {
int[] test = decToBin(12, getBinArray(12));
for(int i = 0; i < test.length; i++){
System.out.println(test[i]);
}
}

public static int[] getBinArray(int number){
int res = number, length = 0;
while(res != 0){
res /= 2;
length++;
}
return new int[length];
}

public static int[] decToBin(int number, int[] array){
int res = number, k = array.length-1;
while(res != 0){
if(res%2 == 0){
array[k] = 0;
}else{
array[k] = 1;
}
k--;
res /= 2;
}
return array;
}
}```

IF we consider the following part of code:

Java Code:
``` public static int[] getBinArray(int number){
int res = number, length = 0;
while(res != 0){
res /= 2;
length++;
}
return new int[length];
}```

Why are they returning the following:

Java Code:
`return new int[length];`
Please explain as I haven't understood it.

Thanks

2. ## Re: Understanding Problem in Code !

Originally Posted by Jack_Tauson_Sr
Why are they returning the following:

Java Code:
`return new int[length];`
Who are "they" and how are they "returning the following"?

If you mean "the compiler" and if you're seeing an error, then by all means you should post the error for us to see and review.

3. Member
Join Date
Nov 2011
Posts
77
Rep Power
0

## Re: Understanding Problem in Code !

"They" means the person who has written the code. I'm trying to understand it. Shouldn't it be returning just "length" ?

Originally Posted by Fubarable
Who are "they" and how are they "returning the following"?

If you mean "the compiler" and if you're seeing an error, then by all means you should post the error for us to see and review.

4. Senior Member
Join Date
Jan 2013
Location
United States
Posts
2,735
Rep Power
4

## Re: Understanding Problem in Code !

Take a look at the method return value. It is int[]. This means that it is returning an array of ints. If it was just returning the length, the return value would just be an int.

Regards,
Jim

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•