Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8983847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:56:37+00:00 2026-06-15T20:56:37+00:00

I am writing a credit card validation program. I am trying to see if

  • 0

I am writing a credit card validation program. I am trying to see if a product is more that 1 digit long (i.e: 10), if it is I need to add the two integers together. For example 10 would be 1 + 0, which equals 1, how do I do this?

This is what I have so far:

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

    //Take in a 16 digit credit card number
    Scanner in=new Scanner (System.in);
    int num[]=new int[16];
    int i=0;


    for (i=0;i<num.length;i++) {
        System.out.println("Please enter a 16 digit credit card number");
        num[i]=in.nextInt();

    }
    if (num.length < 16 || num.length > 16)
        {
            System.out.println("Invalid");
        }
     else
    {

        //multiply every other number by 2, starting with place 16, and find the sum(sum1)
         int num1 = (num[16] * 2);
         int num2 = (num[14] * 2);
         int num3 = (num[12] * 2);
         int num4 = (num[10] * 2);
         int num5 = (num[8] * 2);
         int num6 = (num[6] * 2);
         int num7 = (num[4] * 2);
         int num8 = (num[2] * 2);

         if( num1 > 9)

         int sum1 = (num[16] * 2) + (num[14] * 2) + (num[12] * 2) + (num[10] * 2) + (num[8] * 2) + (num[6] * 2) + (num[4] *2) + (num[2] *2);
         int sum2 = (num[15] + num[13] + num[11] + num[9] + num[7] + num[5] + num[3] + num[1]);

        int totalSum = sum1 + sum2;
        if (totalSum % 10 != 0)
        {
            System.out.println("Invalid card number!!");
        }
        else

        {  
            System.out.println(" Valid Credit Card Number!!");


        }

      }      
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:56:38+00:00Added an answer on June 15, 2026 at 8:56 pm

    I think a simple way would be

    if (num1 > 9) num1 = num1-9
    

    This works if you look at how the original numbers look after multiplying by 2.

    num  num*2  result
    0    0      0
    1    2      2
    2    4      4
    3    6      6
    4    8      8
    5    10     1
    6    12     3
    7    14     5
    8    16     7
    9    18     9
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I spent a month writing an elaborate payment system that handles both credit card
I'm writing a program to validate credit card numbers and I have to use
I am writing a code that collects all the credit card information of each
I'm writing a website that let users submit credit card information and subscribe my
I'm writing an application that needs access to a serial port (it's a credit
I have java application that sending( HTTP post method ) credit card numbers to
i am writing a sim card applet and i need to store data on
im writing payment page and there is 4 textbox for credit card number entry
I am writing a PHP script to take credit card & customer details on
Writing a program for a project. I need to use a ListSelectionListener in order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.