#Verify input of a numerical variable in Java

1 messages · Page 1 of 1 (latest)

shadow hinge
#

I want to verify the input of a numerical variable in Java.

Basically I want diferenciate when the value is 0 in case of this don't get input, or because the user input wat 0.

For now don't send the code because Is so long por the post.

umbral robinBOT
#

<@&987246746478460948> please have a look, thanks.

cyan gull
#

we cant help u without seeing ur code

hexed cape
#

You could either use null or Optionals

cyan gull
#

since its entirely unclear how ur logic for representing "no input" works

#

if u have full control over it and just picked 0 as sentinel value cause u thought its a good idea, the better approach would be to use OptionalInt

hexed cape
#

Since your a novice, I'd suggest using optionals

shadow hinge
#

This is a simplifyed expample.

double num;
String bool;
System.out.println("Do you want insert a number?");
bool=key.next();
if(bool=="Yes"){
num=0;
} System.out.println(num);

I want know when 0 is a input or is the default value by not haben given a value.

cyan gull
#

yeah so use OptionalInt

hexed cape
#

Also pls don't call a String bool

#

And I'm assuming you want to use .equals instead of ==

shadow hinge
hexed cape
#

kk