Saturday, 19 September 2015

Find String Length without using length()

package com.nataraja.b;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class StringLength {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a String:");
String s=br.readLine();

int i=0;

try{
while(true){
s.charAt(i);
i++;
}
}catch(Exception e){
System.out.println(i);
}
}

}

No comments:

Post a Comment