Not sure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Whisperthecat
    New Member
    • Oct 2012
    • 2

    Not sure

    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


    Code:
    import javax.swing.JOptionPane; 
    public class TicketNumber
    {
    public static void main(String[] args)
    {
    final int CHECKDIGIT = 7;
    String ticketString;
    int tickNum, newTickNum, lastDigit, remainder;
    boolean result;
    ticketString = JOptionPane.showInputDialog(null,
    "123454", "Ticket Number Dialog",
    JOptionPane.INFORMATION_MESSAGE);
    tickNum = Integer.parseInt(ticketString);
    lastDigit = tickNum % 10; // gets last digit;
    newTickNum = tickNum / 10; //removes last digit
    remainder = newTickNum % CHECKDIGIT;
    result = (remainder == lastDigit); 
    JOptionPane.showMessageDialog(null,"For ticket number " +
    tickNum + ", last digit is " + lastDigit +
    " and remainder is " + remainder + ",\nso result is " +
    result);
    }
    }
    Last edited by Rabbit; Oct 21 '12, 09:07 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I get different results. Using 1253454 I get "For ticket number 123454, last digit is 4 and remainder is 4,
    so result is true"

    Comment

    • Whisperthecat
      New Member
      • Oct 2012
      • 2

      #3
      were are only allowed to use 6 digits

      Were are only allowed to use 6 digits. I even tried different amount of numbers
      Originally posted by Rabbit
      I get different results. Using 1253454 I get "For ticket number 123454, last digit is 4 and remainder is 4,
      so result is true"

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        That was a mistype. I used the same number you did.

        Comment

        Working...