Guest User

Untitled

a guest
Jan 25th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. boolean valid = false;
  2. while (!valid) {
  3. String s = in.nextString();
  4. try {
  5. a = Double.parse(s);
  6. if (a >= 0) {
  7. valid = true;
  8. }
  9. } catch (NumberFormatException e) {
  10. }
  11. }
  12.  
  13. //OR
  14.  
  15. while (a < 0) {
  16. try {
  17. a = Double.parse(in.nextString());
  18. } catch (NumberFormatException e) {
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment