The Artima Developer Community
Sponsored Link

Java Answers Forum
help on palindrome problem please hurry AP test tomarrow

1 reply on 1 page. Most recent reply: Sep 22, 2009 8:08 PM by George B

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
niles lewis

Posts: 1
Nickname: mlkiii
Registered: Sep, 2009

help on palindrome problem please hurry AP test tomarrow Posted: Sep 22, 2009 11:36 AM
Reply to this message Reply
Advertisement
public class Palindrome
{
public static void main (String [] args)
{

EasyReader console = new EasyReader ();
int input, dig1, dig2, dig3,dig4, dig5;

System.out.println("Enter a five digit number: ");
input = console.readInt();

while(input > 99999 || input < 10000)
{
System.out.println("Entry is invalid due to an incorrect number of digits.");
System.out.print("Entry is invalid due to an incorrect number of digits.");
input = console.readInt();
}


dig1 = input / 10000; // Checks each digit to make sure for a palindrome
dig2 = (input % 10000) / 1000;
dig4 = (input % 10000) % 1000) / 10;
dig5 = (input % 10000) % 1000) % 10;

System.out.println(" " + input + " is a palindrome.");

I'm using Emacs to run and compile this just an fyi, but the dig5 math statement won't tab over and i'm not sure why. I have easyreader in the file and checked my semi-colons. It's really starting to aggravate me and my teacher said we will have one simiallr to this tomarrow for the test.

Oh yeah and a palindrome is a number that reads backwards and forwards. i.e 12321, 45654, and so on. The math should be correct but feel free to check me on that as well.

Thanks
Niles


George B

Posts: 24
Nickname: hmgeorge
Registered: Feb, 2008

Re: help on palindrome problem please hurry AP test tomarrow Posted: Sep 22, 2009 8:08 PM
Reply to this message Reply
You're missing some open parens on the dig4 and dig5 lines.

Flat View: This topic has 1 reply on 1 page
Topic: Finger print Recognition using JAVA [urgent] Previous Topic   Next Topic Topic: difference between an attribute and a property

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use