java - Data type Double is displaying value 0.0 -


this question has answer here:

i have been programming javascript year , half now, , have began learning java syntax. when trying recreate simple program wrote in javascript, have ran trouble when using double data type. here code:


scanner input = new scanner (system.in); int questionstotal; int questionscorrect; double grade; system.out.println("how many questions there in total?"); questionstotal = input.nextint(); system.out.println("how many questions did correct?"); questionscorrect = input.nextint(); grade = questionscorrect / questionstotal * 100; system.out.println("your grade is: " + grade); 

it isn't in snippet, java.util.scanner imported. when user enters values questionstotal , questionscorrect, process fine. however, grade variable not function planned. when printed, displays value of either 0.0, or 1.00, if input should decimal value. have tried using printf rather println, no avail. using wrong data type? can doubles not handle decimal value?

i appreciate feedback on possible semantic error, , apologize lack of experience in field. please let me know if there more information can given. answers appreciated.

try replace line in code:

grade = ((double)questionscorrect) / questionstotal * 100; 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -