I am trying to derive a validation code in which the program would produce a computational answer when executed.For this question the numbers are assumed to be 4 digit numbers. The program may assume it has received a valid 4 digit number. The validation is based on adding the first digit, two times the second digit, and the third digit and considering the last digit of this computation.
Output:
Please enter a 4 digit number: 1234
The last digit is 4
The last digit of the computed result 8 is 8
my code:
import java.util.Scanner;
public class validate {
public static void main(String[] args) {
int first_dig, second_dig, third_dig, last_dig, comp_number,four_digits;
Scanner by;
by=new Scanner(System.in);
System.out.println("Please enter a four digit number");
four_digits=by.nextInt(first_dig + second_dig +third_dig + last_dig);
}
}