F How to find String Length in Java using length function? | CodeTheta

How to find String Length in Java using length function?

March 15, 2018

Below program segment value given by user in program execution time.
Code :
package demo;
import java.util.Scanner;
/*
 * @author www.CodeTheta.com
 */
public class Demo {
    public static void main(String[] args) {
    String UserString;
    System.out.println("Enter any string: ");
    Scanner in = new Scanner(System.in);
    UserString = in.next();
    System.out.println("Length of given string is: "+UserString.length());   
    }   
}

Output :
Enter any string: 
www.codetheta.com
Length of given string is: 17

Below program segment value already assigned.
Code :
package demo;
/*
 * @author www.CodeTheta.com
 */
public class Demo {
    public static void main(String[] args) {
    String UserString = "www.codetheta.com";
    System.out.println("Length of given string is: "+UserString.length());   
    }   

}

Output :
Length of given string is: 17

IDE Used To Test This Code : NetBeans IDE 8.2

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Post a Comment

PRODUCTS

LISTS OF PRODUCTS

SERVICES

SKILLS
SOFTWARE DEVELOPMENT
WEBSITE DEVELOPMENT
WEB HOSTING
BULK SMS SERVICE
SEO SERVICE
ANDROID APPS
QR CODE / BARCODE
HARDWARE SERVICE
OUR WORK AREA