By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

Not sure

P: 2
when asked fro ticket number it says the last number is 7 and theremainder is 4 so the result is false. Can somebody please explain. Thank you


Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane; 
  2. public class TicketNumber
  3. {
  4. public static void main(String[] args)
  5. {
  6. final int CHECKDIGIT = 7;
  7. String ticketString;
  8. int tickNum, newTickNum, lastDigit, remainder;
  9. boolean result;
  10. ticketString = JOptionPane.showInputDialog(null,
  11. "123454", "Ticket Number Dialog",
  12. JOptionPane.INFORMATION_MESSAGE);
  13. tickNum = Integer.parseInt(ticketString);
  14. lastDigit = tickNum % 10; // gets last digit;
  15. newTickNum = tickNum / 10; //removes last digit
  16. remainder = newTickNum % CHECKDIGIT;
  17. result = (remainder == lastDigit); 
  18. JOptionPane.showMessageDialog(null,"For ticket number " +
  19. tickNum + ", last digit is " + lastDigit +
  20. " and remainder is " + remainder + ",\nso result is " +
  21. result);
  22. }
  23. }
Oct 21 '12 #1
Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,422
I get different results. Using 1253454 I get "For ticket number 123454, last digit is 4 and remainder is 4,
so result is true"
Oct 21 '12 #2

P: 2
Were are only allowed to use 6 digits. I even tried different amount of numbers
@Rabbit
Oct 21 '12 #3

Rabbit
Expert Mod 10K+
P: 12,422
That was a mistype. I used the same number you did.
Oct 22 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.