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 184 views
1 answer 175 views
1 answer 144 views
1 answer 119 views
1 answer 123 views
1 answer 121 views
...