The thing I am trying to do is converting a word to numbers according to phone standart. The word will be inputted. An example would be the word "Software" becoming "76389273"
My plan was to convert the string into a list of characters and create a while loop including the switch function. My issue is that I have to store every returned value for every letter.
import java.util.Arrays;
import java.util.Scanner;
import java.util.*;
public class Phonething {
public static void ListTransform(String[] arg) {
Scanner input = new Scanner(System.in);
System.out.println("Enter word");
String word = input.nextLine();
char[] wordArray = word.toCharArray();
String wordList = Arrays.toString(wordArray);
System.out.println(wordList);
}
public static int main(int[] wordList, char t) {
int[] myArr = {};
int value = 0;
int i = 0;
char j = 0;
wordList[i] = j;
while ( i < wordList.length) {
myArr.add(value);
switch (j)
{
case 'A':
case 'B':
case 'C':
case 'a':
case 'b':
case 'c':
value = 2;
break;
case 'D':
case 'E':
case 'F':
case 'd':
case 'e':
case 'f':
value = 3;
break;
case 'G':
case 'H':
case 'I':
case 'g':
case 'h':
case 'i':
value = 4;
break;
case 'J':
case 'K':
case 'L':
case 'j':
case 'k':
case 'l':
value = 5;
break;
case 'M':
case 'N':
case 'O':
case 'm':
case 'n':
case 'o':
value = 6;
break;
case 'P':
case 'Q':
case 'R':
case 'S':
case 'p':
case 'q':
case 'r':
case 's':
value = 7;
break;
case 'T':
case 'U':
case 'V':
case 't':
case 'u':
case 'v':
value = 8;
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
case 'w':
case 'x':
case 'y':
case 'z':
value = 9;
break;
}
i++;
}
return value;
}
public static void main(String[] arg){
System.out.println(myArr);
}
}
I've tried creating an array and updating it by putting it in the while loop but the add operator is not working because of the error "cannot resolve method 'add(int)'". Another issue is that the final code System.out.println(myArr)
"gives the error cannot resolve symbol "'myArr'." That is why I can't print or update the final list.