if ( "проверит_ является_ли_строка_числом")// что писать{ } 

Closed due to the fact that the essence of the question is not clear to the participants of the LFC , Kromster , Enikeyschik , Roman C , freim Jan 30 at 11:34 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

2 answers 2

 String s; //blah-blah if(isNumber(s)) System.out.println("Это число!"); else System.out.println("Это не число!"); public static boolean isNumber(String str) { try { double value=Double.parseDouble(str); return true; } catch (Exception e) { return false; } } 
  • see the answer update - Barmaley

This statement checks if the expression in brackets is true. If so, the action is performed. If not, then comes the next command after the block. Example:

 class Test { public static void main(String[] args){ if(true) { System.out.println("Тест прошёл успешно."); } } } 

Output to console:

 Тест прошёл успешно. 

As you can see, this operator worked successfully, because the expression in parentheses is true.

The else statement Actions written in the else statement will be executed only if the value of if is false. Example:

 class AnotherTest { public static void main(String[] args){ if(false) { System.out.println("Тест прошёл не очень успешно."); } else { System.out.println("Тест прошёл успешно."); } } } 

Output to console:

 Тест прошёл успешно. 
  • @AlexanderChernin This answer was written before the question was edited. Initially, it was not at all clear what the question was. - Enikeyschik