This week's giveaway is in the Spring forum.
We're giving away four 3 month subscriptions to Marco Behler Videos and have Marco Behler on-line!
See this thread for details.
Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

letter to number conversion  RSS feed

 
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
Sheriff
Posts: 10929
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac 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();
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!