1
I wonder how I can check the kind of value that goes into my Scanner
, to return to the user that that entry only receives a number and that he has typed a text or character.
public class WhileChallenge {
public static void main(String[] args)
{
double grades = 0.0;
double grades_total = 0.0;
int grades_amount = 0;
Scanner input_value = new Scanner(System.in);
while(grades != -1)
{
System.out.println("Insert a grade:");
grades = Double.parseDouble(input_value.next().replace(",", "."));
if(grades < 0.0 || grades > 10.0)
{
System.out.println("Out of range value");
}else if(grades >= 0.0 && grades <= 10.0)
{
grades_total += grades;
grades_amount++;
}
//Se a nota for diferente de um número; Pede pro usuário digitar um número
}
System.out.println("Average: " + ((grades_total)/grades_amount));
input_value.close();
}
}
About your other doubt (which I removed because it has nothing to do with the question’s scheduling problem), the website applies the syntax Highlight according to the question tags, and since you already have the [tag:java], the correct syntax will be applied
– hkotsubo