import javax.swing.JOptionPane;
public class MyJavaProgramTask4Exercise3 {
public static void main(String[] args) {
String Namestudent, studentID;
Namestudent = JOptionPane.showInputDialog("Type in a student name: ");
studentID = JOptionPane.showInputDialog(null, "Type in the correspondng ID number: ");
int the_index;
System.out.println(Namestudent + " " +studentID);
System.out.println(Namestudent.charAt(studentID));
}
}
香港專業教育學院被告知要編寫一個程序,允許用戶在鍵入一個學生ID號碼,然後全名,我已經做到了這一點,即時停留在此位,創建一個新的字符串,其中包含ID號中每個數字的索引名稱中的字符...初學Java中使用的charAt並使用用戶輸入來顯示字符
我試圖讓charAt使用學生ID將用戶輸入作爲索引引用顯示Namestudent的字符,但這不是工作,我需要做什麼,而不是感謝
您studentID變量的類型爲字符串,而不是整數的。 – 2014-12-02 16:18:41
假設用戶輸入學號爲一個隨機數,例如3647352,我想創建一個字符串,其中包含他們輸入的名稱中的字符,稱爲「john smith」,並使用ID號作爲「john smith 「 如果你明白的話?說約翰史密斯顯示的輸出將是hsnmh o使用用戶輸入的數字3647352作爲idex .. – paulc01 2014-12-02 16:23:05
@ paulc01你可以很容易地做到這一點,只要確保沒有一個數字會引發indexoutofbounds異常。 – brso05 2014-12-02 16:24:26