import java.util.Scanner;
public class Main {
private static Scanner input = new Scanner(System.in); private static final String INPUT_ERROR1 = "Weight can not be negative or zero!"; private static final String INPUT_ERRORe = "Input can not contain non-numeric characters"; public static void main(String[] args) { double lbs, inches, meters, kgs, bmi; String classification; System.out.println("Calculate BMI"); lbs = inputWeight(); } public static double inputWeight() { double weight = 0.00; do { System.out.print("Enter weight(lbs): "); String weightInput = input.nextLine(); try { weight = Double.parseDouble(weightInput); if (weight <= 0) { System.out.println(INPUT_ERROR1); } } catch (Exception e) { System.err.println(INPUT_ERRORe); } } while (weight <= 0); return weight; }
} In the above code replacing the the current println lines with System.err.println lines breaks my do/while loop. Why is this?
https://stackoverflow.com/questions/66978226/why-does-the-use-of-system-err-println-break-a-do-while-loop April 07, 2021 at 08:47AM
没有评论:
发表评论