text: Program to check if input is an integer or a string | Java program to check if a given string is a valid integer ; Returns true if s is a number else false ; Driver code ; Saving the input in a string ; Function returns 1 if all elements are in range '0 ▁ - ▁ 9' ; Function returns 0 if the input is not an integer
code: import java . io . * ; public class GFG { static boolean isNumber ( String s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( Character . isDigit ( s . charAt ( i ) ) == false ) return false ; return true ; } static public void main ( String [ ] args ) { String str = "6790" ; if ( isNumber ( str ) ) System . out . println ( " Integer " ) ; else System . out . println ( " String " ) ; } }