Hello I am new to java and I am having a hard time on converting the letters from strings to numbers for example, the user will input "I am Okay" and the output will become 901-13015-11-1-25 since, I = 9 space = 0 A = 1 M = 13 space = 0 O = 15 K = 11 A = 1 Y = 25. I tried using switch, but I am having a hard time, because the program will print what I input in the string, well here is the test code I created, I hope someone can help me or give me tips and advices.
import java.util.*;
public class New2
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Input the First string: ");
String fs = input.nextLine();
fstoInt(fs);
System.out.println(fs);
}
public static int fstoInt(String fs) {
int num = 0;
switch (fs) {
case "A":
num = 1;
break;
case "B":
num = 2;
break;
case "C":
num = 3;
break;
case "D":
num = 4;
break;
case "E":
num = 5;
break;
case "F":
num = 6;
break;
case "G":
num = 7;
break;
}
return num;
}
}