Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
public int[] makePi() {
return null;
}
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
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?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!
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;
}
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;
}
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.
>>>
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
result[i] = value / divisor;
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;
}
}
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
System.out.println("pi aray us"+makePi().toString());
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?
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*/
pi aray us[I@74a174a1
rounding is0
Otherwise, if the floating-point number is not an infinity, the floating-point value is rounded to an integer value V, rounding toward zero using IEEE 754 round-toward-zero mode (Â§4.2.3). Then there are two cases:
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.