Find length of string in java without library function length().

 import java.util.*;

public class Main

{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("enter string=");

String str=sc.nextLine();

      int count=0;

      for(char c:str.toCharArray()){

            count++;

      }

      System.out.println("length is="+count);

}

}

output->

enter string=

ved varshney

length is=12

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.