4 Replies - 23546 Views - Last Post: 26 February 2008 - 10:42 PM Rate Topic: -----

#1 CompSciForum854372  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 30
  • Joined: 26-February 08

Convert letters to numbers

Post icon  Posted 26 February 2008 - 09:59 PM

Write a java application that converts letters of the alphabet into their corresponding digits on the telephone. Repeats question until presented with #. And present an error message if its not a a letter or #


i havent gotten very far and need help

[code]
import java.util.Scanner;

public class Number {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter Letter: ");

char letter;
[code]

Is This A Good Question/Topic? 1
  • +

Replies To: Convert letters to numbers

#2 capty99  Icon User is offline

  • i am colt mccoy
  • member icon

Reputation: 98
  • View blog
  • Posts: 10,081
  • Joined: 26-April 01

Re: Convert letters to numbers

Posted 26 February 2008 - 10:13 PM

well what your probably gonna want to do is a for loop... that counts till 10 (if thats how many digits are in your phone #)

and inside that... have a switch or a bunch of if statements and keep track of the total number.

you could keep track of it an an array or really simply in a string.

so initialize a string

this is pseudocode so don't try to run it, just look at what i'm doing :

String phoneNum;

for(int i=0; i < 10; i ++){

if(keyboard.next() == a,b or c){
phoneNum = phoneNum + "1";
}
else if(keyboard.next() == d, e or f){
phoneNum = phoneNum + "2";
}
else {
system.out.println("yeah... thats not a letter, you idiot"}


etc...

then when its done just print out the phoneNum.

This post has been edited by capty99: 26 February 2008 - 10:14 PM

Was This Post Helpful? 0
  • +
  • -

#3 CompSciForum854372  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 30
  • Joined: 26-February 08

Re: Convert letters to numbers

Posted 26 February 2008 - 10:25 PM

thanks
but what i need it to do
is when i give it a letter
give me the corresponding number

ie
enter P
the letter is 7
Was This Post Helpful? 0
  • +
  • -

#4 capty99  Icon User is offline

  • i am colt mccoy
  • member icon

Reputation: 98
  • View blog
  • Posts: 10,081
  • Joined: 26-April 01

Re: Convert letters to numbers

Posted 26 February 2008 - 10:38 PM

yeah
thats what i told you how to do.

if you look at what i wrote,
there are if statements

if the letter a b or c goes in (because there are 3 letters per number on a phone)
then the number 1 comes out (except you will have to look at your cell phone, it might start at number 2)

then the next 3 letters applies to the next number.
Was This Post Helpful? 0
  • +
  • -

#5 GWatt  Icon User is offline

  • member icon

Reputation: 269
  • View blog
  • Posts: 3,067
  • Joined: 01-December 05

Re: Convert letters to numbers

Posted 26 February 2008 - 10:42 PM

You could make an array of strings where each element is the characters on the button.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1