Write a Program in java to find the length of the string

import java.util.Scanner;
public class JavaProgram
{
   public static void main(String args[])
   {
      String str;
      int len;
      Scanner scan = new Scanner(System.in);        
      System.out.print("Enter Your Name : ");
      str = scan.nextLine();
      len = str.length();   
      System.out.print("Length of Entered String is " + len);
   }
}

Output

Enter Your Name :Amit chaudhary

Length of Entered String is 14
 

Explanation

To find the length of the string in Java Programming, you have to ask to the user to enter the string and then find the length of that string using the method length() and display the length value of the string on the output screen as shown in the following program.