Online Java Compiler By
JavaTpoint.com
public class JavaCharacterisLetterOrDigitExample2 { public static void main(String[] args) { // Create four char primitives ch1, ch2, ch3 and ch4. char ch1; char ch2; char ch3; char ch4; // Assign the values to ch1, ch2, ch3 and ch4. ch1 = 'A'; ch2 = '1'; ch3 = '*'; ch4 = '$'; // Create four boolean primitives b1, b2, b3 and b4. boolean b1 = Character.isLetterOrDigit(ch1); boolean b2 = Character.isLetterOrDigit(ch2); boolean b3 = Character.isLetterOrDigit(ch3); boolean b4 = Character.isLetterOrDigit(ch4); String str1 = "The first character '"+ ch1+ "' is a letter or digit: " + b1; String str2 = "The second character '"+ch2+"' is a letter or digit: " + b2; String str3 = "The third character '"+ch3+ "' is a letter or digit: " + b3; String str4 = "The fourth character '"+ch4+ "' is a letter or digit: " + b4; // Printr the values of b1, b2, b3 and b4. System.out.println( str1 ); System.out.println( str2 ); System.out.println( str3 ); System.out.println( str4 ); } }
Output