0

can someone tell me why when I am typing inputDouble(as a double of course), a conditional doesn't let me pass. I tried this also on float type and result is the same.

EDIT: Conditional passing when I'm typing integer.

public static void main(String[] args) {

    Scanner inputDouble = new Scanner(System.in);

    System.out.println("Double");

    if(inputDouble.hasNextDouble()){
        System.out.println("Passed");
    }

    inputDouble.close();

}

Thanks for help.

SOLVED: CODE WAS GOOD I WAS TYPING INPUT WITH DOT INSTEAD OF COMMA

Memes
  • 25
  • 5

1 Answers1

0

Conditional passing when I'm typing integer.

this is known as widening the type, basically, an int type can be converted to a double type safely without any loss of data. The compiler implicitly converts the int to a double type.

as for:

can someone tell me why when I am typing inputDouble(as a double of course), a conditional doesn't let me pass.

As far as I know there is no problem with your code as I have tested it on my IDE and everything seems to be working as expected. However, this could be to do with locality, so make sure that you are using the correct locale for the Scanner.

try using , as the delimiter for double/decimal values rather than .

Ousmane D.
  • 54,915
  • 8
  • 91
  • 126