# Thread: Multiplication with individual elements in an array.

1. Member
Join Date
Oct 2015
Location
Tennessee
Posts
4
Rep Power
0

## Multiplication with individual elements in an array.

So I'm working on this project that is going to validate a credit card using the Luhn check. I'm required to write a ValidateMyCard program that implements a class ValidateCard that uses the Luhn algorithm to check the credit card.

So far I've constructed the ValidateMyCard program. This part asks for a credit card from the user. It then takes this credit card and puts it into an array.
That array is then reversed to aid in the first step of the Luhn algorithm.

From there I created a new class that will contain my Luhn algorithm steps. The first step is to double every second digit and then any doubling that results in a two-digit number will be added together to get a single digit number.

What is the best way to go about multiplying every second element in an array by (2)? I'm unsure of which way to go from here.

Java Code:
```import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;

public class ValidateMyCard {
public static void main (String[] args) {

Scanner input = new Scanner(System.in);

//Declares array list that is 16 digits
int [] numberList = new int[16];

//Tells user to enter a credit card number
System.out.print("Enter a credit card number: ");
String numbers =input.nextLine();

//Converts string into a character array
char[] charArray = numbers.toCharArray();

//reverses the order of the character array into a new array
char[] reversedNumbers = new StringBuilder(new String(charArray)).reverse().toString().toCharArray();

//loop that prints new reversed array
for (int i=0; i < reversedNumbers.length; i ++) {

System.out.println(reversedNumbers[i]);

}

}

class ValidateCard {

}```
Last edited by dtacker; 10-19-2015 at 06:53 PM.

2. ## Re: Multiplication with individual elements in an array.

You should only double every second digit (according to your description), not every digit ...

kind regards,

Jos

3. Member
Join Date
Oct 2015
Location
Tennessee
Posts
4
Rep Power
0

## Re: Multiplication with individual elements in an array.

correct, my mistake.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•