1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Illusion [34]
3 years ago
5

Phone numbers and PIN codes can be easier to remember when you find words that spell out the numberon a standard phone pad. For

example, instead of remembering the combination 5282, you can just think of JAVA.Write a recursive method that given a number, yields all possible spellings (which may or may not be real words).
Computers and Technology
1 answer:
Alik [6]3 years ago
7 0

Answer:

Kindly note that, you're to replace "at" with shift 2 as the brainly text editor can't take the symbol

Explanation:

Here is the completed code for the problem in the question above.

// PinWordEnumerator.java

import java.util.Scanner;

public class PinWordEnumerator {

               public static void main(String[] args) {

                               Scanner scanner = new Scanner(System.in);

                               System.out.print("Enter pin number: ");

                               String num = scanner.nextLine();

                               System.out.println();

                               System.out.printf("The keypad encodings for %s are:%n", num);

                               enumerateWords(num);

               }

               /**

               * method to return a character array containing all possible keypad

               * encodings for a digit in a standard phone

               */

               static char[] getKeysForButton(int n) {

                               switch (n) {

                               case 0:

                                               return new char[] { ' ' }; //returning only space

                               case 1:

                                               return new char[] { '.' }; //returning only dot

                               case 2:

                                               //button 2 contains A, B and C keys

                                               return new char[] { 'A', 'B', 'C' };

                               case 3:

                                               return new char[] { 'D', 'E', 'F' };

                               case 4:

                                               return new char[] { 'G', 'H', 'I' };

                               case 5:

                                               return new char[] { 'J', 'K', 'L' };

                               case 6:

                                               return new char[] { 'M', 'N', 'O' };

                               case 7:

                                               return new char[] { 'P', 'Q', 'R', 'S' };

                               case 8:

                                               return new char[] { 'T', 'U', 'V' };

                               case 9:

                                               return new char[] { 'W', 'X', 'Y', 'Z' };

                               }

                               return null;

               }

               /**

               * method to enumerate words

               *

               * "at"param num

               *            - String containing pin numbers, assuming it has only numbers

               */

               static void enumerateWords(String num) {

                               /**

                               * calling the recursive method to perform the enumeration

                               */

                               if (num != null)

                                               enumerateWords(num, "");

               }

               /**

               * the main method which performs the recursion

               *

               * "at"param num

               *            - current number

               * "at"param text

               *            - text containing converted spellings

               */

               static void enumerateWords(String num, String text) {

                               if (num.length() == 0) {

                                               // base case, displaying the text

                                               System.out.println(text);

                               } else {

                                               // finding the digit at 0th position

                                               int digit = num.charAt(0) - '0';

                                               // finding possible phone keys for this digit

                                               char letters[] = getKeysForButton(digit);

                                               if (letters != null) {

                                                               // looping through all possible keys

                                                               for (int i = 0; i < letters.length; i++) {

                                                                               /**

                                                                               * appending the current letter to the text and calling the

                                                                               * recursive method also neglecting the first letter of

                                                                               * current 'num' string

                                                                               */

                                                                               enumerateWords(num.substring(1), text + letters[i]);

                                                               }

                                               }

                               }

               }

}

/*OUTPUT*/

Enter pin number: 5282

The keypad encodings for 5282 are:

JATA

JATB

JATC

JAUA

JAUB

JAUC

JAVA

JAVB

JAVC

JBTA

JBTB

JBTC

JBUA

JBUB

JBUC

JBVA

JBVB

JBVC

JCTA

JCTB

JCTC

JCUA

JCUB

JCUC

JCVA

JCVB

JCVC

KATA

KATB

KATC

KAUA

KAUB

KAUC

KAVA

KAVB

KAVC

KBTA

KBTB

KBTC

KBUA

KBUB

KBUC

KBVA

KBVB

KBVC

KCTA

KCTB

KCTC

KCUA

KCUB

KCUC

KCVA

KCVB

KCVC

LATA

LATB

LATC

LAUA

LAUB

LAUC

LAVA

LAVB

LAVC

LBTA

LBTB

LBTC

LBUA

LBUB

LBUC

LBVA

LBVB

LBVC

LCTA

LCTB

LCTC

LCUA

LCUB

LCUC

LCVA

LCVB

LCVC

You might be interested in
What is the main purpose of the design of a water hose?
Liono4ka [1.6K]
The water hose is a flexible tube for conveying a liquid, as water. The main purpose of the design of a water hose is functionality.
The reason why the water hose is <span>designed is: to carry fluids from one location to another. the aesthetics is not so important, as the fact that the fluid will be carried without leakage.</span>


7 0
3 years ago
Read 2 more answers
What does mean I can’t turn on my computer and my computer won’t charge at all
Dmitrij [34]

Explanation:

well that happened to me to and what my dad did was to cut the cable and fix it,it worked.Ithink my situation is very different than yours but you cantiue to see what else it says and if you want to you can text me back.

5 0
3 years ago
Why might a variable used for output have to be of a different type then a variable used for input? ​
bija089 [108]
After you declare a variable, you can assign a value to a variable. Assigning a value to a variable means storing a value to a variable. To assign a value, use the equal sign: var age; ... In this one line above, we declare a variable called age when we assign the value 55.
3 0
3 years ago
help asapp!!!!!! give the technical name means (write the name in one word) . the feature of virus which copies itself..​
Sloan [31]

Answer:

if a computer is made out of many copies it can cause a virus with a definition of a tro Jan by a virus

Explanation:

what follows is a brief history of the computer virus and what the future holds for this once when a computer is made multiple copies of it's so several reducing malicious intent here but animal and prevade fit the definition of a Trojan buy viruses worms and Trojans paint the name Malwar as an umbrella term

5 0
3 years ago
In the Bullets and Numbering dialog box, the size of bullets and numbers is set in __________.
wlad13 [49]

The answer is C, percentage of text size.

5 0
4 years ago
Read 2 more answers
Other questions:
  • Binary search requires that data to search be in order. true or false
    5·1 answer
  • A spreadsheet program of a computerized version of _______
    14·1 answer
  • If I put a short clip from a copyrighted video to Facebook and make it only viewable to friends, is that illegal?
    12·1 answer
  • Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and returns the index of the last occu
    10·1 answer
  • How to delay sending an email in office 365
    6·1 answer
  • A(n ________ is information that is passed to a function, and a(n ________ is information that is received by a function.
    15·1 answer
  • Which operating system became obsolete with the arrival of more advanced graphical user interfaces
    12·1 answer
  • Write a paragraph on 'Save Earth Save Life.'​
    12·1 answer
  • Consider the following code segment:
    13·1 answer
  • WAP to input the rating of a movie, and print as per the given criteria:
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!