Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Quick java question/help
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedQuick java question/help

 Post Reply Post Reply
Author
Zedy View Drop Down
Newbie
Newbie


Joined: 21 April 2008
Status: Offline
Points: 2
Direct Link To This Post Topic: Quick java question/help
    Posted: 21 April 2008 at 9:28pm
Hi all,
 
I'll get to the point.  I've been steadily working on my java project which involves the luhn algorithm and the checking of credit card validity.  Apparently every college student has taken to the web regarding this one either recently or in past years...I see lots of threads regarding this stuff.
 
Either way, I have a text book, I go to class, I am learning this stuff.  I'm having trouble with only one part of the whole dang thing.  I've got myself mixed up between strings and int values.  I could really use some help (rather a new set of eyes to look and go "yeah move x over here and your good")
 
I won't post all of my code as I spent enough time on it...rather keep it as my own.  The below is just the first bit, where I challenge for a 16 digit credit card number.  I'm doing something wrong but my brain is fried.  Any ideas?  I self taught myself constructors this weekend...so I'm not using any as of yet, but would think this is a case that might make things quite a bit easier :)
 
import java.util.Scanner;
import java.util.*;
import java.lang.Math;
public class Luhn22
{
 public static void main(String[] args)
 {
  Scanner keyboard = new Scanner(System.in);

       System.out.print ("Please enter your credit card number: ");
  System.out.println();

  String s = keyboard.next(); // I tried nextInt but I cannot use the charAt function later with integer value

  int i = s.length(String, 16); // This is where I go wrong...I can't mask it differently and I attempt to change to integer value
  int sum = 0; // Part of my later algorithm
        int b = sum; // Part of my later algorithm
        int n = 9; // Part of my later algorithm
 
  while (i != 16) // This isn't working either...I need a full proof method to check 16 digits, but it's a start for me and very basic
     {
    System.out.println("Please enter another credit card number: ");
    s = keyboard.next();
     }
 
I understand your not a java forum or a bunch of experts...but if you have a few minutes at work to take a glance, would be appreciated.
 
Thanks,
 
--Steve
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.