Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Cannot Find Symbol in For Loop

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4502
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 26602
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4502
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 72929
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic