Java Program to Find Length of String

« Previous Program Next Program »

Find Length of String

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.

Java Programming Code to Find Length of String

Following Java Program ask to the user to enter a string to find its length using the length() method, then display the result on the screen:

/* Java Program Example - Find Length of String */
import java.util.Scanner;

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

When the above Java Program is compile and executed, it will produce the following output:

Java Program find length of string

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

Java Online Test

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.