Here is the problem
Problem:
1. You are confusing the variable n looping, so I add in sample variable to maintain the input value.
2. if((digit1 == digit5) && (digit2 == digit4))
; I deleted the semicolon.
3. total is same as sum ==> both use for display so I erase the sum variable.
Here is the solution:
CODE
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Foo Soon
*/
public class palindrome {
public static void main(String[] args)
{
int n,digit1,digit2,digit3,digit4,digit5;
int sample;
for (sample=10000; sample <= 99999;sample++)
{
n=sample;
digit5 = n % 10; // 0
n = n / 10; // 1000
digit4 = n % 10; // 0
n = n /10; //100
digit3 = n % 10; //0
n = n / 10; //10
digit2 = n % 10; //0
n = n / 10; //1
digit1 = n % 10; //1
n = n / 10; //0
String total = String.valueOf(digit1)+String.valueOf(digit2) +String.valueOf (digit3)+String.valueOf(digit4)+String.valueOf(digit5);
if((digit1 == digit5) && (digit2 == digit4))
{
System.out.println(" Palindrome is" + total);
}
}
}
}
Next time, Please put your code into <code> tag
Thank you
This post has been edited by fsloke: 17 Oct, 2008 - 06:24 PM