java - Why does this not work? I am trying to write a small program that prompts a user to enter any double value -



java - Why does this not work? I am trying to write a small program that prompts a user to enter any double value -

so have prompt user come in double value if not double value supposed flush buffer prompt user value, print value if double.

double value; scanner sc = new scanner(system.in); system.out.println("enter double value: "); value = sc.nextdouble(); while (!sc.hasnextdouble()) { sc.nextline(); system.out.println("enter valid value: "); value = sc.nextdouble(); } system.out.println(value);

swap order of loop,

// value = sc.nextdouble(); while (!sc.hasnextdouble()) // <-- while don't have double { sc.nextline(); system.out.println("enter valid value: "); // value = sc.nextdouble(); } value = sc.nextdouble(); // <-- here

java osx netbeans

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -