Bottlecaps
Bottlecaps

Reputation: 129

Trying to write a Java program that finds words with ascending characters

Meaning words with characters in alphabetical order. It reads these words from a notepad file, with one on each line. I've written the code for it, but I can't figure out why it won't work. I compare the characters in a for loop, but the boolean value I use stays as I initialize it and does not change. Below is my code, I'td be great if someone could tell me what I'm doing wrong.

The extra variables are for keeping track of the average and total number of words. I left out the variable initialization for the sake of readability. If I initialize test as true, the program prints every word, but if I initialize it as false the program just ends.

Upvotes: 0

Views: 79

Answers (2)

Juned Ahsan
Juned Ahsan

Reputation: 68715

One problem in your code is that your for loop condition seems to be reversed. Change this:

  for (n=0; n>theWord.length() -1; n++) 

to

  for (n=0; n < theWord.length() -1; n++)

Upvotes: 0

Pepe
Pepe

Reputation: 6480

for (n=0; n>theWord.length() -1; n++)

Should be

for (n=0; n < theWord.length() -1; n++)

Upvotes: 1

Related Questions