Many security systems use a check digit. Bumble Bank uses the following check di
ID: 671233 • Letter: M
Question
Many security systems use a check digit. Bumble Bank uses the following check digit system for its bank account numbers. Add the 3 digits. If the sum is even, the check digit should be 0. If the sum is odd, the check digit should be 1. Write a program in Java to check for valid bank account numbers. Ask for the bank account number. If the number given is 4 digits and the ones digit is a correct check digit, tell the user that is a valid account number. If the number is not a 4 digit number or if the ones digit is not the correct check digit report a fake.Explanation / Answer
package mani;
import java.util.Scanner;
public class Problem2 {
public static void main(String[] args) {
String accno;
Scanner scan=new Scanner(System.in);
System.out.print("What is your bank account number? ");
accno=scan.next();
if(Integer.parseInt(accno)>=1000&&Integer.parseInt(accno)<=9999){
int sum=0;
for(int i=0;i<3;i++){
sum=sum+Character.getNumericValue(accno.charAt(i));
}
if(sum%2==1){
if(accno.charAt(3)=='1'){
System.out.println(accno+" is a valid account number.");
}
else{
System.out.println(accno+" is a fake account number!");
}
}
else if(sum%2==0){
if(accno.charAt(3)=='0'){
System.out.println(accno+" is a valid account number.");
}
else{
System.out.println(accno+" is a fake account number!");
}
}else{
System.out.println(accno+" is a fake account number!");
}
}
else{
System.out.println(accno+" is a fake account number!");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.