java - How do I make sure that the user enters a number between 0 and 10 only? -


i have made array subjects called subjectname. goal of code make sure user enters valid numbers (between 1.0 , 10.0). don't know how that. created if statement , make return if subjectname isn't between 0 , 10 doesn't work. not sure how can tackle this.

edit: subjectname names of each subject string. subjectgrade double. both arrays. forgot mention that.

this code:

for (int = 0; < subjectname.length; i++) {             scanner input = new scanner(system.in);             system.out.print("what grade for: " + subjectname[i] + "? ");             subjectgrade[i] = input.nextdouble();              if ( subjectgrade[i] < 0.0 || subjectgrade[i] > 10.0) {                 return;             } 

you should use while loop. ask question while grade invalid.

while(subjectgrade[i] < 0.0 || subjectgrade[i] > 10.0) {     system.out.print("what grade for: " + subjectname[i] + "? ");     subjectgrade[i] = input.nextdouble(); } 

(goes instead of if)

anyway, mistake return statement doesn't repeats last command or anything. returns value function...


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -