我有點難倒在這裏,一直試圖找出一段時間。這是作業,儘管我想學習編碼。在這裏,我必須將用戶輸入的字符串轉換爲大寫字母,然後使用電話鍵盤系統將這些大寫字母轉換爲數字(2 = ABC等)。從字符串輸入返回數字,Java
我已經得到了這麼多,但我不確定我的下一步應該是什麼。任何想法都非常感謝,提前感謝。
package chapter_9;
import java.util.Scanner;
public class Nine_Seven {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a string: ");
String s = input.next();
// unsure what to do here, know i need some sort of output/return
// statement
}
public static int getNumber(char uppercaseLetter) {
String[] Keypad = new String[10];
Keypad[2] = "ABC";
Keypad[3] = "DEF";
Keypad[4] = "GHI";
Keypad[5] = "JKL";
Keypad[6] = "MNO";
Keypad[7] = "PQRS";
Keypad[8] = "TUV";
Keypad[9] = "WXYZ";
for (int i = 0; i < Keypad.length; i++) {
// unsure what to do here
}
return (uppercaseLetter);
}
}
Java沒有'foreach'嗎? – nmichaels
@nmichaels:它對某些事情有用(查找'Iterator'),但這對於這項任務來說是一種矯枉過正。 –
@nmichaels它的確如此,但代碼表明OP希望返回foreach循環中不可用的索引變量。 –