How to calculate and print the length of a given string using java

public class StringLengthCalculator {
    public static void main(String[] args) {
        String str = "Java Programming";
        int length = calculateStringLength(str);
        System.out.println("Length of the string: " + length);
    }

    private static int calculateStringLength(String str) {
        return str.length();
    }
}

 

Post your Answer