Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes letter to number conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "letter to number conversion" Watch "letter to number conversion" New topic
Author

letter to number conversion

Jade Davidson
Ranch Hand

Joined: Oct 12, 2001
Posts: 64
I hope someone can help me. I am doing a program that involves converting the letters in someone's name to numbers. Our teacher gave us a conversion grid, and I worked out a formula for converting the letters using modular arithmetic (see below).
What I want to do is to go through the name, converting each letter to a number, according to the formula shown. I thought that a String array would be the best way to do this, but I keep getting errors. The source code is below:

(edited by Cindy to format code)

[This message has been edited by Cindy Glass (edited November 15, 2001).]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4458
    
    6

Jade,
A few hints:
- nameArray.length == 1, not 13
- the expression (('a' - 'a') % 9) + 1 results in an int value of 1. This is evaluated at compile time and will never change inside the for-loop. You cannot assign the value 1 to a String variable.
Good luck!
Junilu


Junilu - [How to Ask Questions] [How to Answer Questions]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You could convert the String to a char Array using the toCharArray() method of String, and THEN walk through the chars doing the conversion etc.
String name = "Brian Candido"; //or better yet = args[0];
char[] myNameArray = name.toCharArray();


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
 
subject: letter to number conversion