#Verify input of a numerical variable in Java
1 messages · Page 1 of 1 (latest)
<@&987246746478460948> please have a look, thanks.
we cant help u without seeing ur code
You could either use null or Optionals
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
Since your a novice, I'd suggest using optionals
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.
yeah so use OptionalInt
Also pls don't call a String bool
And I'm assuming you want to use .equals instead of ==
Yes, I do it this quickly, that's what I writed so.
kk