Results 1 to 2 of 2
  1. #1
    irnie1994 is offline Member
    Join Date
    Aug 2011
    Posts
    28
    Rep Power
    0

    Default Telephone Number To Digits

    import java.util.*;
    public class number5 {

    static Scanner console = new Scanner(System.in);

    public static void main(String[] args) {

    String str;
    char letter;




    System.out.println("Enter phone number expressed in letters: ");
    str = console.next();
    System.out.println();




    if ((letter >= 'A' || letter >= 'a') && (letter <='Z' || letter <= 'z'))
    {

    switch (str.charAt(0))
    {
    case 'A': case 'a': case 'B': case 'b':
    case 'C': case 'c': System.out.print("2");
    break;
    case 'D': case 'd': case 'E': case 'e':
    case 'F': case 'f': System.out.print("3");
    break;
    case 'G': case 'g': case 'H': case 'h':
    case 'I': case 'i': System.out.print("4");
    break;
    case 'J': case 'j': case 'K': case 'k':
    case 'L': case 'l': System.out.print("5");
    break;
    case 'M': case 'm': case 'N': case 'n':
    case 'O': case 'o': System.out.print("6");
    break;
    case 'P': case 'p': case 'Q': case 'q': case 'R': case 'r':
    case 'S': case 's': System.out.print("7");
    break;
    case 'T': case 't': case 'U': case 'u':
    case 'V': case 'v': System.out.print("8");
    break;
    case 'W': case 'w': case 'X': case 'x': case 'Y': case 'y':
    case 'Z': case 'z': System.out.print("9");
    break;
    default: System.out.print(" ");

    }
    switch (str.charAt(1))
    {
    case 'A': case 'a': case 'B': case 'b':
    case 'C': case 'c': System.out.print("2");
    break;
    case 'D': case 'd': case 'E': case 'e':
    case 'F': case 'f': System.out.print("3");
    break;
    case 'G': case 'g': case 'H': case 'h':
    case 'I': case 'i': System.out.print("4");
    break;
    case 'J': case 'j': case 'K': case 'k':
    case 'L': case 'l': System.out.print("5");
    break;
    case 'M': case 'm': case 'N': case 'n':
    case 'O': case 'o': System.out.print("6");
    break;
    case 'P': case 'p': case 'Q': case 'q': case 'R': case 'r':
    case 'S': case 's': System.out.print("7");
    break;
    case 'T': case 't': case 'U': case 'u':
    case 'V': case 'v': System.out.print("8");
    break;
    case 'W': case 'w': case 'X': case 'x': case 'Y': case 'y':
    case 'Z': case 'z': System.out.print("9");
    break;
    default: System.out.print(" ");
    }
    switch (str.charAt(2))
    {
    case 'A': case 'a': case 'B': case 'b':
    case 'C': case 'c': System.out.print("2");
    break;
    case 'D': case 'd': case 'E': case 'e':
    case 'F': case 'f': System.out.print("3");
    break;
    case 'G': case 'g': case 'H': case 'h':
    case 'I': case 'i': System.out.print("4");
    break;
    case 'J': case 'j': case 'K': case 'k':
    case 'L': case 'l': System.out.print("5");
    break;
    case 'M': case 'm': case 'N': case 'n':
    case 'O': case 'o': System.out.print("6");
    break;
    case 'P': case 'p': case 'Q': case 'q': case 'R': case 'r':
    case 'S': case 's': System.out.print("7");
    break;
    case 'T': case 't': case 'U': case 'u':
    case 'V': case 'v': System.out.print("8");
    break;
    case 'W': case 'w': case 'X': case 'x': case 'Y': case 'y':
    case 'Z': case 'z': System.out.print("9");
    break;
    default: System.out.print(" ");

    }

    }
    else
    System.out.println("Invalid input");

    }

    }

    what was wrong here??

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Telephone Number To Digits

    what was wrong here??
    You tell us...does it compile? Are there exceptions? Does it misbehave? I can't speak for everyone, but myself - I'm not good at guessing, reading minds, or reading code which is not properly formatted within the code tags.

Similar Threads

  1. Reads a number and prints it's binary digits, need help :)
    By Aimforthehead in forum New To Java
    Replies: 2
    Last Post: 10-04-2011, 07:39 PM
  2. need help with Number Pyramid with Double Digits
    By SmellyFoot in forum New To Java
    Replies: 5
    Last Post: 03-29-2011, 01:04 PM
  3. Replies: 1
    Last Post: 01-19-2011, 10:23 PM
  4. Separating the digits of given number
    By lb2 in forum New To Java
    Replies: 5
    Last Post: 09-09-2010, 06:29 AM
  5. Count number of digits in string using scanner
    By wendysbiggy in forum New To Java
    Replies: 35
    Last Post: 01-20-2010, 06:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •