Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean valid = false;
- while (!valid) {
- String s = in.nextString();
- try {
- a = Double.parse(s);
- if (a >= 0) {
- valid = true;
- }
- } catch (NumberFormatException e) {
- }
- }
- //OR
- while (a < 0) {
- try {
- a = Double.parse(in.nextString());
- } catch (NumberFormatException e) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment