2021年1月20日星期三

Java exception, why do my variables seem to stop working? [duplicate]

I've recently enrolled in java classes and recently come across an issue that has led me to no results while googling. This is the code with my issues:

        try{          System.out.println("Enter weight in lbs: ");          double num1 = inputDevice.nextDouble();          System.out.println("Enter height in inches: ");          double num2 = inputDevice.nextDouble();          }          catch(InputMismatchException e){              System.out.println("Please enter a valid numerical value");          }          double bmi = bmi(num1, num2);  

My issue is adding the exception, the code works fine yet I want to add an exception in case letters get used instead of numerical values. The error I receive after I attempt to run the code involves the last line, where it states "num1, num2 cannot be resolved to a variable" any and all help would be appreciated!

https://stackoverflow.com/questions/65820233/java-exception-why-do-my-variables-seem-to-stop-working January 21, 2021 at 10:06AM

没有评论:

发表评论