I am taking an intro to prorgamming class and I have come across a question to which I have no clue of the answer. I am usually very objected to simply putting a homework question out to receive an answer, but I have exhausted all other methods of understanding why this is happening.
We're using DrJava which has a small pane where you can just input code and get an instant result. They have me enter the following:
int x = 1 / 3; System.out.println(x);
and
double d1 = 1 / 3; System.out.println(d1);
Both of which give me 0 and 0.0 respectivly as the result. I expected it for the first one, but I expected when I changed the type to double or float it would give me 0.33, not 0.0. I am totally lost as to why this is happening. Any help would be greatly appreciated. Thanks for any bit of help.
2006-09-10
12:21:55
·
3 answers
·
asked by
loudgrrl4_ever
2
in
Computers & Internet
➔ Programming & Design