This is the first solution to find the length of a given alpha numeric or string value. This approach uses direct string class length method.
import java.util.Scanner;
public class LengthOfAlphaNumeric {
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("resource")
Scanner inpAlphanumeric= new Scanner(System.in);
//Input a string or alpha numberic
System.out.println("Enter String or Alpha numeric value=");
String inpStr=inpAlphanumeric.next();
System.out.println("The entered string is="+inpStr);
// Use the length function
System.out.println("The Length of the string is="+inpStr.length());
}
}
Output:
Enter String or Alpha numeric value=
4err%$53k
The entered string is=4err%$53k
The Length of the string is=9

Leave a comment