我在分配給我的這個初學者Java程序時遇到了麻煩,對于Java來說我是完全陌生的,并且在這個特定程序中遇到了很多麻煩。這些是說明:您的程序應提示用戶輸入一個n位數字作為學生ID,然后顯示輸入的ID的有效性。您可以假設n的范圍為6到10(含10和10)。校驗和數字是學生ID的一部分。您的算法是將輸入ID中最右邊的數字與計算出的校驗和數字進行匹配。如果不匹配,則您的程序應報告輸入的ID無效。例如,輸入的ID 1234567無效,因為計算出的第7位數字是1(=(1 *(digit1)+ 2 *(數字2)+ 3 *(數字3)+ 4 *(數字4)+ 5 *(數字5)+ 6 *(數字6))%10),并且與實際的第7位數字7不同。但是,如果輸入的ID為1234561,則您的程序應顯示一條接受消息。我要嘗試的第一步是從用戶輸入中讀取沒有空格的每個數字,就像要有空格一樣。然后,我嘗試獲取分配給數字1,數字2等的變量的每個數字,等等。import java.util.Scanner;public class H4_Ruby{public static void main(String[] args){// this code scans the the user input Scanner scan = new Scanner(System.in); System.out.println("Please enter a student ID between 6-10 digits"); String nums = scan.nextLine(); String[] studentIdArray = nums.split(" "); int[] studentID = new int [studentIdArray.length]; for (int i = 0; i < studentIdArray.length; i++) { studentID[i]= Integer.parseInt(studentIdArray[i]); System.out.print(studentID[i] + ","); }}到目前為止,這是我的代碼...
添加回答
舉報
0/150
提交
取消