Results 1 to 7 of 7
  1. #1
    Zedy is offline Member
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    Default Quick Java question/help

    Yes, I'm another college student seeking help. Yes I have a textbook, that I read and self-teach myself. Yes I go to class. Yes my brain is fried working on my own luhn algorithm and credit card validation java program. Not asking for pure answers, just got myself mixed up in int and String values. Any ideas would help me on how to correct this little mess or an idea on where to look. I self taught myself constructors over the weekend but I'm still a bit nervous on trying to implement any, so I'm not using any here. The whole idea behind them is a bit...logically disorienting anyways. Any ideas on the below?

    I need to check the incoming value...but if I use keyboard.nextInt I cannot check each digit with charAt later to verify using the luhn algorithm. So I made a string and converted to int to check the length. I think I need to change my while boolean statement to boolean values, does this mean I should use more variables? I'll try doing this in the mean time...

    Thanks,

    --Steve

    Java Code:
    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();
    
    
    		int i = s.length(16); [COLOR="SeaGreen"]// This is the problem I think!![/COLOR]
    		int sum = 0;
            int b = sum;
            int n = 9;
    
    		while (i != 16) [COLOR="SeaGreen"]// This also giving me problems[/COLOR]
    
    			  {
    
    				System.out.println("Please enter another credit card number: ");
    				s = keyboard.next();
    			  }

  2. #2
    rico16135 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    why are you putting a 16 in the s.length() value? leave it blank.

  3. #3
    Zedy is offline Member
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    Default

    Hrm...still giving me issues between my Integers and Strings.

    --Steve

  4. #4
    rico16135 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    You should post the error, be more specific as to the error. I can't help if I don't know what's wrong.

  5. #5
    fireball2008 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    int i = s.length();
    this should fix the problem.

  6. #6
    fireball2008 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    Java Code:
    
    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();
    
    
    		int i = s.length(); // This is the problem I think!!
    		int sum = 0;
            int b = sum;
            int n = 9;
    
    		while (i != 16) // This also giving me problems
    
    			  {
    
    				System.out.println("Please enter another credit card number: ");
    				s = keyboard.next();
    			  }}}
    compile fine on my java machine!

  7. #7
    rico16135 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

Similar Threads

  1. Wanna make 5 quick bucks?
    By GodiaN in forum Java Applets
    Replies: 5
    Last Post: 01-21-2008, 08:15 PM
  2. Quick Help Please! Can't Run Code!!
    By VinceGuad in forum Eclipse
    Replies: 4
    Last Post: 01-16-2008, 04:54 AM
  3. Quick Stupid Question
    By bluekswing in forum New To Java
    Replies: 7
    Last Post: 01-08-2008, 07:35 PM
  4. Quick Job required in Java
    By taxman in forum Jobs Offered
    Replies: 0
    Last Post: 01-02-2008, 12:46 PM
  5. Quick Question (Functions)
    By ibanez270dx in forum New To Java
    Replies: 2
    Last Post: 11-16-2007, 02:42 AM

Posting Permissions

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