ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
public class Class1{
public static void main(String args[]) {
double a[]={3.0,2.0,3.0};
int i;
double h;
for (i=0;i<3;i++){
if (i %2 ==0 ){
h=Math.ceil(Math.exp(Math.log(a[i])*2));//this is where im lost
}
else{
h=Math.ceil(Math.exp(Math.log(a[i])*2));
}
System.out.print(h);
System.out.print(" ");
} }
}
I dont know why, but i work it out on paper and i get 6.0 4.0 6.0 and i really dont know why, as far as i know i%2 is equal to 0 because i is initiated to 0.
if anyone can help me out on this, i think the math.ceil has to do something on it too, but i just cant find out what, id really appreciate
thanx
edit* [i forgot about the if statement, plz excuse the issue
some test stuff that i got, but we go through every single problem, and this is one that i just get, this is not the first problem i post, its been a few. But what i want to know is how it works and why i get the answer i get, and where it is that im lost
ok you just got me even more lost, all i want to know is why im getting a 9.0 as the first number when i compile, i am getting a 6.0, and i am not suppossed to, i compile and run, and my results are [9.0 ,4.0, 9.0] and if i do it on paper, i get 6.0 4.0 and 6.0, why is it that i get that on paper, and why is it that the correct answer it 9.0, 4.0, and 9.0?
yea i got it, my bad, it was just i hadnt really noticed the Math.log, although i didnt know, but know i get, so thanx for realz, i really appreciate the help.
-Jerry V.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.