Java Program to find length of a string

Get a String and count the characters in the string

Sample Input 1:

Hello

Sample Output 1:

5

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

public class Hello { public static void main(String args[]) { //Write your code here } }

Program or Solution

				
			
					
//To Find The Length Of The String...

import java.util.*;

class Program
{
   public static void main(String args[])
   {
      String str;
      Scanner sc=new Scanner(System.in);

     System.out.println("Enter The String:");
     str=sc.next();

     int len=str.length();

     System.out.println("The Length Of The String Is:"+len);

  }
}
			
				
			

Program Explanation

Comments