I'm having trouble with this beginner java program that was assigned to me, I'm completely new to java and I'm having a lot of trouble with this particular program. These are the instructions:
Your program should prompt users to enter an n-digit number as a student ID, and then display the validity of the entered ID. You can assume n will be in the range of 6 and 10 inclusive. The checksum digit is part of student ID. Your algorithm is to match the rightmost digit in the entered ID with the computed checksum digit. If there is no match, then your program shall report the entered ID being invalid. For example, the entered ID 1234567 is invalid because the computed 7th digit is 1 (= (1 * (digit1) + 2 * (digit 2) + 3 * (digit 3) + 4 * (digit 4) + 5 * (digit 5) + 6 * (digit 6)) % 10) and is different from the actual 7th digit which is 7. However, if the entered ID is 1234561 your program shall display a message of acceptance.
The first step I'm trying to do is to read each number from the user's input that doesn't have spaces, as if it were to have spaces. Then I'm trying to get each of those numbers assigned to the variable that is digit 1, digit 2, ... etc. to compute.
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] + ",");
}
}
That is my code so far...