• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

letter to number conversion

 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 8894
81
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic