java - Why is my answer showing as Infinity? -
java - Why is my answer showing as Infinity? -
i sort-of new bear me.
i creating programme allows user come in in scores of piece of coursework , exam score , total grade calculated. values entered have between 1 , 10. coursework work 40% , exam worth 60%. values 1-10 have converted percentages , believe infinity error occurring.
this code (there 'if' , 'else' statements later in code think i'll ok that. ignore final classification @ bottom):
import javax.swing.joptionpane; public class question3 { public static void main(string[] args) { string coursework, exam; coursework = joptionpane.showinputdialog("please come in coursework score out of 10:"); exam = joptionpane.showinputdialog("please come in exam score out of 10"); double courseworkdoub, examdoub, courseworkperc, examperc, finalmark; courseworkdoub = double.parsedouble(coursework); courseworkperc = (courseworkdoub / 0.25); examdoub = double.parsedouble(exam); examperc = (examdoub / (10 / 60)); finalmark = (courseworkperc + examperc); joptionpane.showmessagedialog(null, "final mark: " + finalmark + "\nfinal classification ", "result", joptionpane.information_message); } }
courseworkperc
, examperc
seem problem. want able show percentage 2 decimal places. example, 5 out of 10 in coursework (worth 40%) = 20.00% , 5 out of 10 in exam (worth 60%) = 30.00% hence overall grade 50.00%
hopefully makes sense. appreciate advice given. thanks
it's due integer partition in line:
examperc = (examdoub / (10 / 60));
10
, 60
integers, (10 / 60)
results in integer reply -- 0
.
if 1 of them double literal, e.g. 10.0
(or equivalently, 10d
or (double)10
), double result -- 0.166666
.
example fix:
examperc = (examdoub / (10.0 / 60));
java double percentage
Comments
Post a Comment