Welcome to Dream.In.Code
Become a Java Expert!

Join 150,422 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,101 people online right now. Registration is fast and FREE... Join Now!




5 digit Palindromes

 
Reply to this topicStart new topic

5 digit Palindromes, Write a program to create an array of size 25 and fill it with 5-difit

JRDemo
17 Mar, 2008 - 01:07 AM
Post #1

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 0

java

public class MOD7Exercise1
{
public static void main(String args[])
{
int palindrome[] = new int[25];
int n=0;
for(int i =0; i < 99999; i++)
{
String s1 = Integer.toString(i);
StringBuilder sb=new StringBuilder(s1);
if(s1.equals(sb.reverse().toString()))
palindrome[i] = (int) (Math.random () * 99999) + 1;
{
palindrome[n++]=i;
if(n == 25)
{
break;
}
}
}
for(int i=0; i<25; i++)
{
if(palindrome[i]%2==0)
{
System.out.println("Palindrome "+i+"="+palindrome[i]+ " is even");
}
else
{
System.out.println("Palindrome "+i+"="+palindrome[i]+ " is odd");
}
}
}
}

here is the code. I am not getting 5 digit palindromes, but it is compiling and showing the odd and even. I can't think in what direction the start chasing. Road block in the brain!

I didn't get the code to indent. Sorry for that. I know it makes it harder to read. I think I was suppose to attach it not cut and paste. OOPS
User is offlineProfile CardPM
+Quote Post

1lacca
RE: 5 Digit Palindromes
17 Mar, 2008 - 01:38 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
Welcome to D.I.C. JRDemo, I hope you'll find the answers you are looking for here!
However please post programming questions in the related programming forum next time, and when you post code put it inside code tags: code.gif

Could you explain what this part of the code is supposed to do?
java

palindrome[i] = (int) (Math.random () * 99999) + 1;
{
palindrome[n++]=i;
if(n == 25)
{
break;
}
}

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:31PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month