Monday 2 March 2020

Java: Check given character is letter or not

'Character.isLetter' method is used to check whether given character is letter or not.

App.java
package com.sample.app;

public class App {

	private static void printLetter(char charz) {
		if(Character.isLetter(charz)) {
			System.out.println("'" + charz + "' is a letter");
		}else {
			System.out.println("'" + charz + "' is not a letter");
		}
	}
	
	public static void main(String args[]) {
	
		printLetter('a');
		printLetter('@');
		
		printLetter('\t');
		printLetter(' ');
		printLetter(',');
		
		
	}
}

Output

'a' is a letter
'@' is not a letter
'	' is not a letter
' ' is not a letter
',' is not a letter


You may like

No comments:

Post a Comment