Java program to find the length of a given string
GD.java
import java.util.Scanner;
class GD
{
    public static void main(String args[])
    {
        String s;
        System.out.println("———————————————————————————————————————————");
        System.out.println("Program to find the length of a given string");
        System.out.println("———————————————————————————————————————————");
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter the string ");
        s=sc.nextLine();
        System.out.println("\nEntered string is "+s);
        int l=s.length();
        System.out.println("\nThe length of ("+s +") = "+l);
        System.out.println("———————————————————————————————————————————");
    }
}
Output
godarda@gd:~$ javac GD.java
godarda@gd:~$ java GD ——————————————————————————————————————————— Program to find the length of a given string ——————————————————————————————————————————— Enter the string Hello, World! Entered string is Hello, World! The length of (Hello, World!) = 13 ——————————————————————————————————————————— godarda@gd:~$
Java program to find the length of a given string
GD.java
class GD
{
    public static void main(String args[])
    {
        String s1="KODINGWINDOW";
        int length=0;
        for(String s2:s1.split(""))
        {
            length++;
        }
        System.out.println("Length of a string is: "+length);  
    }
}
Output
godarda@gd:~$ javac GD.java
godarda@gd:~$ java GD Length of a string is: 12 godarda@gd:~$
Comments and Reactions