Thanks for taking the time to open this. I am just starting to learn Java and cannot seem to get past a point in the program I'm currently working on. I'm making a credit card verifier, where you enter the numbers and an algorithm deems it valid or invalid. I have that part down, but I cannot figure out how to adjust when given a different length credit card.
Let me explain further: The program has to be able to accept cards between 13 an 16 digits in length. I'm currently using an array (which I know cannot be adjusted once created) to perform my algorithm. This accepts and stores 16 numbers and then performs what I need it to. I need to somehow allow my user to input a number or character that sets the array to the length of what they have already entered. RIght now, if they stop after 14, my program is still looking for numbers until it hits 16. I need the user to be able to stop the input and for the program to be able to adjust for the input (since it depends on the indexes of the input to verify it)
This is what I have so far, the algorithm isn't imposed yet. However, you do see that I am trying to use the numbers.length command to get the index of the last number (whether that is 13, 14, etc.) and multiply it by 2. Is this acceptable?
Any help is appreciated.
import java.util.Scanner;
import java.util.Arrays;
public class Exercise05 {
public static void main(String []args) {
Scanner input= new Scanner(System.in);
int i;
int[] numbers;
double round1;
numbers= new int [16];
for(i=0 ;i < numbers.length; i++){
numbers[i]=input.nextInt();
}
System.out.print("The Credit Card digits you entered are: ");
System.out.println(Arrays.toString(numbers));
double round1= (numbers[numbers.length] * 2);
System.out.println( "you " + round1 );
if( numbers[0]==4)
System.out.println("This is a Visa");
else if( numbers[0]==5)
System.out.println("This is a Mastercard");
else if( numbers[0]==6)
System.out.println("This is a Discover Card");
else if( numbers[0]==3 && numbers[1]==7 )
System.out.println("This is a Mastercard");
else
System.out.println("Invalid card");
}
}