好的,所以这个程序应该使用用户定义的方法来查找字符串中每个字符的数值并将其分配给键盘上的数字......即 1800FLOWERS 到 18003569377
当我尝试编译时,我在 getNumber 方法的最后得到一个“缺少返回语句”。有人可以帮我吗
import java.util.Scanner; //import scanner object
public class phone
{
public static void main(String [] args)
{
int i = 0;
Scanner scan= new Scanner(System.in);
System.out.println("Enter a phone number");
String number = scan.nextLine();
String upperCaseLetter = number.toUpperCase();
int length = number.length();
if (i <= length)
{
char result = number.charAt(i);
int carat = getNumber(result);
System.out.print(""+carat+"");
i++;
}
}
public static int getNumber(char result)
{
if (result == 65 || result == 66 || result == 67)
{
result = 2;
return result;
}
else if (result == 68 || result == 69 || result == 70)
{
result = 3;
return result;
}
else if (result == 71 || result == 72 || result == 73)
{
result = 4;
return result;
}
else if (result == 74 || result == 75 || result == 76)
{
result = 5;
return result;
}
else if (result == 77 || result == 78 || result == 79)
{
result = 6;
return result;
}
else if (result == 80 || result == 81 || result == 82 || result == 83)
{
result = 7;
return result;
}
else if (result == 84 || result == 85 || result == 86)
{
result = 8;
return result;
}
else if (result == 87 || result == 88 || result == 89 || result == 90)
{
result = 9;
return result;
}
}
}