Length of the String without using java built in length method


import java.io.*;
public class a
{
public static void main(String args[])throws Exception
{
String s ;
int i=0;

DataInputStream dd=new DataInputStream(System.in);
System.out.println("Enter a string");
s=dd.readLine();
s=s.trim();
try
{for(i=0;i>=0;i++)
s.charAt(i);
}
catch(Exception e)
{
System.out.println("the length is : "+i);
}

}
}

Post a Comment