• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Cannot Find Symbol in For Loop

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning Javahorns!

I'm having issue with the current code. For some reason even initializing letter in the for loop, the compiler says that it cannot letter in the method. Why is this? How do I solve this issue?

 
Saloon Keeper
Posts: 3462
149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jenny,

welcome to the Ranch and enjoy the stay!

First of all: your code is badly formatted and that makes it very hard to follow. Do you use an IDE? If so, it takes just one click of the mouse to reformat your code. Please do so!

Then about the error you are getting. Well, the first one I noticed is in line 36:

Can you spot the error here? It is a very small error and easy to overlook!
 
Jenny Flair
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Piet,

I use a text-editor with a compiler to work with code, namely TextPad.

I have fixed the first error with the semi-colon ending on the for loop.

It compiles now but an ArrayOutOfBoundsException error occurs. I wonder how this is since the maximum total in the alphabet is 26 but it's taking input based on how many letters there are in the sentence, so that section shouldn't be issue.

It's line 28 or 54 that has this problem
 
Sheriff
Posts: 24635
56
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


It may be related to this line of code, which doesn't do what the comment claims it does.
 
Piet Souris
Saloon Keeper
Posts: 3462
149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. I would even say: it IS related to what Paul remarks. And check if there are other similar mistakes.
 
Marshal
Posts: 65467
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jenny Flair wrote: . . . I use a text-editor with a compiler to work with code, namely TextPad. . . .

Does your editor support automatic indentation? Your indentation is very inconsistent, and that can cause you no end of confusion. Also always use {} for if‑elses, etc. or the same reason. See our formatting suggestions.

. . . ArrayOutOfBoundsException error occurs.

You mean one of these? Make sure your numbers used as array indices are always in the range 0...25 inclusive for a 26‑element array. It is possible to do arithmetic with chars, but you may find methods of the Character class, e.g. isLetter() or isLowerCase() etc. easier to use (if they are permitted).

. . . It's line 28 or 54 that has this problem

I can't see any such error in lines 28 and 54; the line numbers in what you posted must be different.

And welcome to the Ranch again Javahorns! I have never been called that before
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!