比较java中的输入值

Ike*_*nsa -1 java

我正在尝试比较输入值.这是我想说的样本.

           if(text.input != float)
           {
              //code to calculate
           }
Run Code Online (Sandbox Code Playgroud)

我不想允许输入数字以外的值.它是否正确?

Ale*_*lov 6

你应该做点什么

try {
  float value = Float.valueOf(text.input);
  // Do something with value - it's OK.
} catch (NumberFormatException e) {
  // text.input is not a float, handle appropriately...
}
Run Code Online (Sandbox Code Playgroud)

  • 什么是_user-define_?`text.input`显然应该是`java.lang.String`. (3认同)