daily pastebin goal
35%
SHARE
TWEET

Untitled

a guest Oct 17th, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. public class StudentID {
  3.     public static void main(String[] args){
  4.         Scanner scan = new Scanner(System.in);
  5.         System.out.print("What is your student number? ");
  6.         String studentNumber = scan.next();
  7.         int numberLength = studentNumber.length();
  8.         if(numberLength == 6)
  9.         {
  10.             int integerStudentNumber = Integer.parseInt(studentNumber);
  11.  
  12.             int seventhDigit = 0;
  13.             for(int i = 6; i>= 1;i--){
  14.                int oneNumber = integerStudentNumber % 10;
  15.                seventhDigit = i * oneNumber + seventhDigit;
  16.  
  17.                integerStudentNumber = integerStudentNumber / 10;
  18.             }
  19.             System.out.println("The seventh digit is: "+ seventhDigit%10);
  20.  
  21.         }
  22.  
  23.         if(numberLength == 7)
  24.         {
  25.             String firstSix = studentNumber.substring(0, 6);
  26.  
  27.             String lastOne = studentNumber.substring(6);
  28.  
  29.  
  30.             int firstSixStudentNumber = Integer.parseInt(firstSix);
  31.  
  32.             int lastOneStudentNumber = Integer.parseInt(lastOne);
  33.  
  34.  
  35.             int seventhDigit = 0;
  36.             for(int i = 6; i>= 1;i--)
  37.             {
  38.                 int oneNumber = firstSixStudentNumber % 10;
  39.                 seventhDigit = i * oneNumber + seventhDigit;
  40.  
  41.                 firstSixStudentNumber = firstSixStudentNumber / 10;
  42.             }
  43.  
  44.             if(seventhDigit%10 == lastOneStudentNumber)
  45.             {
  46.                 System.out.print("The student number is correct");
  47.             }
  48.             else{
  49.                 System.out.print("Student number is incorrect");
  50.             }
  51.  
  52.         }
  53.  
  54.         }
  55.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top