Posts

Showing posts with the label wrapper class

Checking Character only in String - Java 2024 - MNC - Technical Interview

 Checking if the String contains Character only     Get the input from the user using Scanner class. Then create a method to check the following condition. 1. Check if the string is null or empty, if it is directly return false. 2. Iterate the String using for loop inside the for loop, use the if for condition checking. 3. Condition is check the Character only, for this use the Character Wrapper class, in that we have  isAlphabetic() method to check the character. 4. This method will return true or false based on it is character or not. Code: package com.dinatechy.challange; import java.util.Scanner; public class CheckCharacter { public static void main(String[] args ) { //Check the String only contains Character or Not Scanner scan = new Scanner(System. in ); System. out .print( "Enter the String : " ); String data = scan .next(); scan .close(); boolean isChar = checkOnlyCharacter ( data ); System. out .println( isChar ? "Yes...