Login
Order Now
Support
theprogrammingassignmenthelp

Java Program - The international standard letter/number mapping found on the telephone

  • 12th May, 2019
  • 12:26 PM

Java Program - The international standard letter/number mapping found on the telephone

Program

import java.util.Scanner;
public class problem3 {
    public static void main(String args[]) {
Scanner input = new Scanner(System.in);
//storing commandline argument in s
        String s = args[0];
//converting it into character
        char ch = s.charAt(0);
//converting it to uppercase
        ch = Character.toUpperCase(ch);
        int number = 0;
//conditions for each letter
        if (Character.isLetter(ch))
        {
            if (ch >= 'W'){
                number = 9;}
            else if (ch >= 'T'){
                number = 8;}
            else if (ch >= 'P'){
                number = 7;}
            else if (ch >= 'M'){
                number = 6;}
            else if (ch >= 'J'){
                number = 5;}
            else if (ch >= 'G'){
                number = 4;}
            else if (ch >= 'D'){
                number = 3;}
            else if (ch >= 'A'){
                number = 2;}
//Displaying results
            System.out.println("The corresponding number is " + number);
        }
        else
            System.out.println(ch + " is an invalid input");
    
}
}
 

Share this post