It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Hi,

I was working on below challenge to find 6 at first and last position of array.

http://codingbat.com/prob/p167011

i am failing tests. not sure how to approach this challenge. please advise

I was working on below challenge to find 6 at first and last position of array.

http://codingbat.com/prob/p167011

```
public int[] makePi() {
return null;
}
```

i am failing tests. not sure how to approach this challenge. please advise

```
int[] piDigits={3, 1, 4};
return piDigits;
```

```
public int[] makePi() {
int[] piDigits={3, 1, 4};
return piDigits;
}
```

above passed all the tests. Not sure if something needs to be done with 22/7 which is pi calculation value right?please advise

You can get the value of pi from Math.PI

Not sure if something needs to be done with 22/7Why do you think that? It are exercises to let you create and work with arrays. Not to let you calculate pi!

But in case you would like to:

```
public int[] makePi() {
int[] result = new int[3];
int value = 2200/7;
int divisor = 100;
for (int i=0; i<3; i++) {
result[i] = value / divisor;
value = value % divisor;
divisor /= 10;
}
return result;
}
```

or with the use of Math.PI:

```
public int[] makePi() {
int[] result = new int[3];
int value = (int)(Math.PI * 100);
int divisor = 100;
for (int i=0; i<3; i++) {
result[i] = value / divisor;
value = value % divisor;
divisor /= 10;
}
return result;
}
```

Then doing integer division by 100 gives the first digit, 3.

Modulo 100 gives you the last two digits in an integer, 14.

and so on...

i wonder why we need to multiply by 100 and then devide by hunded and for loop?If you wonder, why don't you just try without doing that? I encourage you to learn by experimenting with the code.

( You will see that your result will be the array [3,0,0] )

If you perfrom 22/7 you get just the int 3. If you take 2200/7 you get 314.

But - although interesting - that's all about calculation, which I can't imagine was the purpose of that exercise...

```
>>>
for (int i=0; i<3; i++) {
result[i] = value / divisor;
value = value % divisor;
divisor /= 10;
}
in this for loop we are getting 3 when i=0
then 1 when i=1
then 4 when i=2
then loop exists right.
I see how first element of array being pouplated by 3 using [quote]result[0] = value / divisor;[/quote]
but not clear on how 1 and 4 being populated into result[1] and result[2]
>>>value = value % divisor;
this results 14 right which is the reminder due to this modulo operation
[b]divisor /= 10;[/b]
what above line means and does?
is it like
divison =divison/10; which is 1?
please advise
```

is like

divisor = divisor/10;

http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.26.2

divisor = 100

314 / 100 = 3

314 % 100 = 14

divisor = 10

14 / 10 = 1

14 % 10 = 4

divisor = 1

4 / 1 = 4

4 % 1 = 0

>> not clear on how 1 and 4 being populated into result[1] and result[2]

by this line of code:

```
result[i] = value / divisor;
```

Btw, I don't know which IDE you use, but

```
public class Test50 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("pi aray us"+makePi().toString());
}
public static int[] makePi() {
int[] result = new int[3];
int value = 2200/7;
int divisor = 100;
for (int i=0; i<3; i++) {
result[i] = value / divisor;
value = value % divisor;
divisor /= 10;
}
return result;
}
}
```

i am using RAD IDE. I tried as above getting gibberish output. please advise.

How to see and print all the pass values while debugging.

```
pass one (i=0)
divisor = 100
314 / 100 = 3
314 % 100 = 14
pass two (i=1)
divisor = 10
14 / 10 = 1
14 % 10 = 4
pass three (i=2)
divisor = 1
4 / 1 = 4
4 % 1 = 0
```

By putting breaki point and step over step into will help me to see each value individually but i want to see all the values of all pass same time like above you have given preferably without system outs all over the places. please advise

Set your breakpoint. Double-click to the left of the line number and you'll see a blue circle.

Run your app with the debugger.

Click the Variables tab. Here you can watch the values of variables change as you step through the statements.

Step over each statement to execute it and stop.

Repeat until you understand the code.

I thought i supposed to be 0.1(1/10). please advise

Divisor.jpg

(int)0.1 == 0

http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17.2

Right. That's what I meant by debugging.

That way you can see the moment (the place in your code) where the program doesn't react the way you had in mind.

>> but i want to see all the values of all pass same time (...) without system outs all over the places.

That's not possible (unless you store them in a list/array/map/whatever and print that out after the loop)

>> i wonder why the divisor showed 0 just after coming out of for loop

That's because we're working with int's.

2200 / 7 = 314 (and not 314.285714... as it would be when we were using double's)

1 / 10 = 0 (and not 0.1 as it would be when we were using variables of the type double)

System.out.println("pi aray us"+makePi().toString());

above not prinitng array elements clearly. How to print array elements. please advise

http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.3

Which is fortunate for the operation of the http:#a40614445 algorithm.

http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.3i was going through above link. Not able to find yet where it says how int rounding happens?

If the value is zero, it rounds down. If the value is 1, it rounds to the nearest integer.

```
public class Test50 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("pi aray us"+makePi().toString());
System.out.println("rounding is"+(int)0.6);
}
public static int[] makePi() {
int[] result = new int[3];
int value = 2200/7;
int divisor = 100;
for (int i=0; i<3; i++) {
result[i] = value / divisor;
value = value % divisor;
divisor /= 10;
}
return result;
}
}
/*pass one (i=0)
divisor = 100
314 / 100 = 3
314 % 100 = 14
pass two (i=1)
divisor = 10
14 / 10 = 1
14 % 10 = 4
pass three (i=2)
divisor = 1
4 / 1 = 4
4 % 1 = 0*/
```

i see it prints 0 only. But i still wonder that documentation is so elaborate which makes hard to find what i want

pi aray us[I@74a174a1

rounding is0

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Integer division is pretty standard, (at least for positive integers)

http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17.2

http://mathworld.wolfram.com/IntegerDivision.html

http://en.wikipedia.org/wiki/Division_%28mathematics%29#Of_integers