• Post Reply Bookmark Topic Watch Topic
  • New Topic

index problem  RSS feed

 
kunal acharya
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


now ,the problem is last two lines are throwing outofbound exceptions,even before inititalizing string s.Any suggestions???
Thank you

[Fixed the code tags. Again. See UseCodeTags for details.]
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kunal acharya wrote:the problem is line 1 and line 2...

Actually, the problem is that your code is very hard to read. Please UseCodeTags (←click).

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston is right - that code is just about impossible to read. I would be willing to bet you have a full keyboard - why on earth would you choose "l" as a variable name?

Next, since we have no idea what was input, how are we supposed to help diagnose?

All I can suggest is that you put in a LOT of "System.out.println()" statements. Print out what c contains. print out what l contains. then go from there.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16058
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One problem is that you have a semi-colon ; at the end of this line, which most likely does not belong there.

This line says: "if c[0] is equal to c[l-1], then do nothing".
 
kunal acharya
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok...let me share my doubt in just one line:
s.charAt(0) is throwing outofbound exception even i have not initialized string s from standard input.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kunal acharya wrote:even i have not initialized string s from standard input.

How have you initialised it then ?
If all you've done is
String s = "";
then there will be no char at position 0

And if that's not the case, then see the third paragraph of Fred's reply.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kunal acharya wrote:
s.charAt(0) is throwing outofbound exception even i have not initialized string s from standard input.

you should actually post the entire exception stacktrace and like Adrian says, explain what that String s contains when you are doing a charAt(0) method invocation on it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!