How to find length of a string in Java

Java programming provides builtin function to find the length of any string. Remember when we use string function to find its length then spaces are included in it.

Source Code  


package com.ancodingpoint.ww;
import java.util.Scanner;

public class String_Length {

   
    public static void main(String[] args) {
        Scanner input = new Scanner (System.in);
        String sentence = "";
        System.out.println(" Enter Your Story ...");
        sentence = input.nextLine();
        System.out.print(" The Total Characters included spaces  in your story are :");
        System.out.println(sentence.length());
       
    }
    
}

Output of the Program

Java String Programming




Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment