How to implement the C isxdigit() function in Java

1 Answer

0 votes
public class Program {
    public static boolean isXDigit(char character) {
		if (Character.isDigit(character))
			return true;
		else if ("ABCDEFabcdef".indexOf(character) > -1)
			return true;
		else
			return false;
	}
    
    public static void main(String args[]) {
        // 0123456789ABCDEFabcdef
        
        System.out.println(isXDigit('3'));
        
        System.out.println(isXDigit('A'));
        
        System.out.println(isXDigit('G'));
    }
}


  
/*
run:
  
true
true
false
  
*/

 



answered Mar 1, 2024 by avibootz

Related questions

1 answer 174 views
1 answer 160 views
1 answer 136 views
1 answer 113 views
1 answer 116 views
1 answer 113 views
...