bibiki 18 Posting Whiz

Hey JamesCherrill, I still am confused. rather than:

int valueOfExpression = num;
num = num + 1;

I thought, what actually happnes is:

    int num = 0;
    //when we write num = num++;, what I think happens is:
    int valueOfExpression = num;
    num = num;
    valueOfExpression = num + 1;
    //and this leaves num 0, instead of incrementing it to 1.

stultuske, you're right, there is no reason for any emotional reaction on my part for Java's contradiction to my expectations. And, one of the reasons I like being a programmer is that there is no room for arguing with the compiler. But there is nothing wrong with saying Java si wrong either man. Alright, take care.

bibiki 18 Posting Whiz

I have encountered this same issue once, and I happened to have access to someone that other people told me is a guru at the time. And I do take that guy for a guru, but this exact question puzzled him also, so all you much respected Java Forum helpers are a little wrong with your reactions to Tokamak, let me tell you straight forward.

Anyways, this is how the guy I mentioned went about the issue:
he used javap to see the assembly equivalent of the code (correct me if I am wrong with the interpretation of what he did), and tried to see what is actually going on.

Now, with all that specs referencing going on, what the conversation seems to have made necessary is to discuss how the specs are actually implemented.

I do agree with Tokamak that the c++ example he mentioned is closer to how my intuition expects the code to work than Java. I know that the question is solved, but I just wanted to put in my two cents.

AND, as someone that has been paid 12 salaries as a programmer (that is my experience), but is very interested to make sense of ins and outs of programming, here is how I'd speculate and try to make sense of this issue:

Java is very rigid in discerning between Objects and primitive types. If ++ was a method, and num an object, the num = num++; would have behaved the way Tokamak and …

bibiki 18 Posting Whiz

not only is it not a question. it is an advertisement and closer to spam than any question gets.

bibiki 18 Posting Whiz

if you just want to avoid using if-else for all 25 cases, you can use switch-case.

bibiki 18 Posting Whiz

String s = "k" and char c = 'k' are different. you either need to tursn String s into a char or char c into a String before comparing. use proper methods for comparing though. hope that helps!

bibiki 18 Posting Whiz

you can do that without a loop. there is a formula I dont remember. however, here you have the code with the loop.

public class Interest{

public static void main(String[] args){
double x = 0;
for(int i = 1; i<4; i++){
x = (x +100) * 1.00417;
}

System.out.println(x);

}
}
javaAddict commented: Giving code is against the rules -1
masijade commented: The formula doesn't matter as the assignment was, probably, specifically for a loop. That said, what does the OP learn when you do the work. -2