wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes why am I getting an infinite loop? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why am I getting an infinite loop?" Watch "why am I getting an infinite loop?" New topic
Author

why am I getting an infinite loop?

Jade Davidson
Ranch Hand

Joined: Oct 12, 2001
Posts: 64
I am still doing the letter to number conversion thing.
I tried to loop through the name using charAt() and I got an infinite loop. Why is this happening?
import java.util.*;
import java.lang.*;
public class Name {
public static void main(String[] args) {
String name = "Brian Candido";
String s = name.toLowerCase();
for (int i = 0; i < s.length(); i++){
i = ((s.charAt(i) - 'a') % 9) + 1;
System.out.print(i);
}

William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

Simplify.
Have one variable be your counter and another variable be your character that you want to print.
There is no reason to try and use one variable to do two jobs.


Please ignore post, I have no idea what I am talking about.
Rene Marot
Greenhorn

Joined: Jun 27, 2001
Posts: 9
You use i as an index and to read your char. Use i only as the loop index.
Bye.
 
jQuery in Action, 2nd edition
 
subject: why am I getting an infinite loop?
 
Similar Threads
For Loop mystery
Infinite loop
Collections for Loop
Why infinite loop
small IO problem