I’m trying to divide an integer by an integer in Java and return a long result. I tried the following, but I keep getting “0”.
System.out.println(Long.valueOf(5) / Long.valueOf(18));
System.out.println((long)5 / (long)18);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It seems everyone has given the right answer, but you should note you can also do
Where f makes it a float
where d makes it a double