Hello Everyone, Can anyone know, How can I simplify this code? I check every input for an error, but I think the code is duplicated. I am using this java compiler - https://www.interviewbit.com/online-java-compiler/ Can anyone suggest whats wrong with this code?
long houseNumberOfFloors; while (true) { System.out.print("Enter valid house number of floors: "); try { houseNumberOfFloors = Long.parseLong(br.readLine()); } catch (NumberFormatException e) { continue; } if (FlatAttrValidator.checkHouseNumberOfFloors(houseNumberOfFloors)) { break; } } Integer houseNumberOfLifts; while (true) { System.out.print("Enter valid house number of lifts: "); try { houseNumberOfLifts = Integer.parseInt(br.readLine()); } catch (NumberFormatException e) { continue; } if (FlatAttrValidator.checkHouseNumberOfLifts(houseNumberOfLifts)) { break; } }
What is the code for the FlatAttrValidator class?