Results 1 to 7 of 7
Thread: Quick Java question/help
- 04-21-2008, 10:44 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 2
- Rep Power
- 0
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(); }
- 04-22-2008, 12:54 AM #2
Member
- Join Date
- Apr 2008
- Posts
- 28
- Rep Power
- 0
why are you putting a 16 in the s.length() value? leave it blank.
- 04-22-2008, 02:28 AM #3
Member
- Join Date
- Apr 2008
- Posts
- 2
- Rep Power
- 0
Hrm...still giving me issues between my Integers and Strings.
--Steve
- 04-22-2008, 02:51 AM #4
Member
- Join Date
- Apr 2008
- Posts
- 28
- Rep Power
- 0
You should post the error, be more specific as to the error. I can't help if I don't know what's wrong.
- 04-22-2008, 03:29 AM #5
Member
- Join Date
- Apr 2008
- Posts
- 28
- Rep Power
- 0
int i = s.length();
this should fix the problem.
- 04-22-2008, 03:32 AM #6
Member
- Join Date
- Apr 2008
- Posts
- 28
- Rep Power
- 0
compile fine on my java machine!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(); }}}
- 04-22-2008, 03:40 AM #7
Member
- Join Date
- Apr 2008
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Wanna make 5 quick bucks?
By GodiaN in forum Java AppletsReplies: 5Last Post: 01-21-2008, 07:15 PM -
Quick Help Please! Can't Run Code!!
By VinceGuad in forum EclipseReplies: 4Last Post: 01-16-2008, 03:54 AM -
Quick Stupid Question
By bluekswing in forum New To JavaReplies: 7Last Post: 01-08-2008, 06:35 PM -
Quick Job required in Java
By taxman in forum Jobs OfferedReplies: 0Last Post: 01-02-2008, 11:46 AM -
Quick Question (Functions)
By ibanez270dx in forum New To JavaReplies: 2Last Post: 11-16-2007, 01:42 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks