The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Ur problem solved - Remove ; in for loop

Posted by Jeganathan S on October 20, 2000 at 2:59 AM


public class a2n2
public static void main (String [] args)throws Exception
String s;

BufferedReader kb = new BufferedReader(new InputStreamReader(;
System.out.println("Enter your Name:");
s = kb.readLine();

int count= s.length();
int pos=0;
char chs;

for(pos = 0; pos < count; pos++)

chs = s.charAt(pos);
System.out.println("Character :"+ chs);

Also, u r comparing the integer pos with character chs and there
is a logical error that u r incrementing ur count(which is the
length of the string), if u increase the count then automatically
u will lose the length of the string and if u try accessing
that it will throw u StringOutofBoundsException as u r trying out
of the String. And one more error i found is while incrementing
count u have done like count+ and it should be count++.

r u happy now
Jeganathan S

  • thanks julio torres October 20, 2000 at 10:06 PM (0)

Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us