Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-22-2008, 12:44 AM
Member
 
Join Date: Apr 2008
Posts: 2
Zedy is on a distinguished road
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

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); // 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(); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-22-2008, 02:54 AM
Member
 
Join Date: Apr 2008
Posts: 28
rico16135 is on a distinguished road
why are you putting a 16 in the s.length() value? leave it blank.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-22-2008, 04:28 AM
Member
 
Join Date: Apr 2008
Posts: 2
Zedy is on a distinguished road
Hrm...still giving me issues between my Integers and Strings.

--Steve
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-22-2008, 04:51 AM
Member
 
Join Date: Apr 2008
Posts: 28
rico16135 is on a distinguished road
You should post the error, be more specific as to the error. I can't help if I don't know what's wrong.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-22-2008, 05:29 AM
Member
 
Join Date: Apr 2008
Posts: 28
fireball2008 is on a distinguished road
Send a message via AIM to fireball2008
int i = s.length();
this should fix the problem.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-22-2008, 05:32 AM
Member
 
Join Date: Apr 2008
Posts: 28
fireball2008 is on a distinguished road
Send a message via AIM to fireball2008
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!
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-22-2008, 05:40 AM
Member
 
Join Date: Apr 2008
Posts: 28
rico16135 is on a distinguished road
? isn't that what I told him to do?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wanna make 5 quick bucks? GodiaN Java Applets 5 01-21-2008 09:15 PM
Quick Help Please! Can't Run Code!! VinceGuad Eclipse 4 01-16-2008 05:54 AM
Quick Stupid Question bluekswing New To Java 7 01-08-2008 08:35 PM
Quick Job required in Java taxman Jobs Offered 0 01-02-2008 01:46 PM
Quick Question (Functions) ibanez270dx New To Java 2 11-16-2007 03:42 AM


All times are GMT +3. The time now is 05:01 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org