Question: In Java, please answer the following: A school assigns a six-digit number to each student. In order to check if the student types in their

In Java, please answer the following:

A school assigns a six-digit number to each student. In order to check if the student types in their student number correctly, a seventh digit can be determined from the other digits using the following number: 7th digit = (1*(1st digit) + 2*(2nd digit) + ... + 6*(6th digit))%10 If the number is typed incorrectly, the check digit will fail to match 90% of the time. Write an interactive program that prompts the user for a six-digit student number and prints out the check digit for that number.

The following is an incorrect solution:

import java.util.*; public class MyClass { public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.println("Enter the six-digit student number: "); int number = in.nextInt(); int r, check = 0, length = 6; while(number > 0){ r = number % 10; check += r * length; length--; number /= 10; } check = check % 10; System.out.println("The check digit for the number: " + check); } }

Expected Result:

Entersixdigitstudentnumber:0  
 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!