3 Replies - 1230 Views - Last Post: 14 March 2012 - 04:43 AM Rate Topic: -----

#1 nikke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-March 12

convertion of alphabet letters to numbers in java

Posted 14 March 2012 - 02:27 AM

hello!!!! help me.. asap...
this is the problem..
how to get five alphabets from user. the program should then be able to translate each letters to its equivalent number. example, a to 1, b to 2, c to 3 until z to 26. note: the program should accept capital letter and small letter like a or A.
Is This A Good Question/Topic? 0
  • +

Replies To: convertion of alphabet letters to numbers in java

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2555
  • View blog
  • Posts: 10,660
  • Joined: 20-September 08

Re: convertion of alphabet letters to numbers in java

Posted 14 March 2012 - 02:40 AM

Read the javadoc for java.lang.Character. Your first job is to ensure that all characters are treated as lower case (or upper case)

This post has been edited by g00se: 14 March 2012 - 02:56 AM

Was This Post Helpful? 0
  • +
  • -

#3 menukadevinda  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

Re: convertion of alphabet letters to numbers in java

Posted 14 March 2012 - 02:46 AM

If I am correct ,each characters of alphabet has unique number in in ASCI.
like A is 65, B is 66 so on. a=97, b=98 and so on.

so when user input a character u can check whether it is capital or simple.
Let's say it is simple then we know it is 97 to 122 range. then we can deduce 96 from the converted chart to decimal.

so you know what the number is now.

as an example if it is b,

b is converterd to decimal then it is 98 and deduce 98-96 and u get the answer is 2.

you have to find the suitable methode to convert char to decimal in java. since i am not a java programmer.

[url]http://www.asciitable.com/[/url]
Was This Post Helpful? 1
  • +
  • -

#4 burakaltr  Icon User is online

  • D.I.C Regular

Reputation: 91
  • View blog
  • Posts: 274
  • Joined: 07-November 10

Re: convertion of alphabet letters to numbers in java

Posted 14 March 2012 - 04:43 AM

Cast 'a' to Integer to get 97
Cast 'A' to Integer to get 65
The following letters obey this order 'a'-'z' and 'A' to 'Z'

Read input, check if between 97 and 122
Check if between 65 and 90

Subtract accordingly

This post has been edited by burakaltr: 14 March 2012 - 04:44 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1