Forums Register Login

Greatest 3-digit Palindrome Number

+Pie Number of slices to send: Send
Hey guys i have wrote the code to find Greatest Palindrome 3-digit number.

it just doesnt display greatest, it displays all the palindrome numbers encountered.

i Just want you guyz to help me out here :

1) how do i find greatest number in this
2) i've used compare method, is there any other method that can reduce computation & memory of the programme, please feel free to share it.

Here goes the code :



Array is not being used in the programme, but i've kept it because i had plans of doing it through arrays, but coudnt find a way to break the number & store it in array.

Any suggestion for my code would be greatly appreciated

please guyz help me out
1
+Pie Number of slices to send: Send
The largest palindromic number of N digits is simply 10^N - 1. That is, N consecutive nines.

But if you want to pretend you don't know that and actually have to search for it, then my advice would be to start with the largest N-digit number there is, see if it's a palindrome, and if not, then decrement it and try again, and keep doing that until you find it.

I strongly suggest that you break your program down into methods. Putting that much in one method makes it very hard to understand what your program is doing, and main() should never do more than just kick off the real work of the app.

As for putting the digits into an array, you could use / and % to get the individual digits, or you could turn it into a String and use String's methods to get individual characters.
+Pie Number of slices to send: Send
It seems from your program that you are trying to find the largest palindrome that is the product of two 3-digit numbers, which is differrent from what you are asking here. There are numerous probelms in your code. However, before we get into the code, what exactly are you trying to do?
+Pie Number of slices to send: Send

Jayesh A Lalwani wrote:It seems from your program that you are trying to find the largest palindrome that is the product of two 3-digit numbers, which is differrent from what you are asking here. There are numerous probelms in your code. However, before we get into the code, what exactly are you trying to do?



i m trying to find out the largest 3 digit Palindrome number.

The answer of this is :
906609
Thats it i m just trying to find out this number.

But i get all the list, i coudnt find a way to find largest palindrome from the outputs produced.

But all those SOP are just for my reference , otherwise i just need that number.

Can you please list all the problems with the code, i m new to this algorithm stuff.
i m just practicing here.
+Pie Number of slices to send: Send

Jeff Verdegan wrote:The largest palindromic number of N digits is simply 10^N - 1. That is, N consecutive nines.

But if you want to pretend you don't know that and actually have to search for it, then my advice would be to start with the largest N-digit number there is, see if it's a palindrome, and if not, then decrement it and try again, and keep doing that until you find it.

I strongly suggest that you break your program down into methods. Putting that much in one method makes it very hard to understand what your program is doing, and main() should never do more than just kick off the real work of the app.

As for putting the digits into an array, you could use / and % to get the individual digits, or you could turn it into a String and use String's methods to get individual characters.



No i m not trying to find that.
sorry to not properly being able to explain.

According to your example, say N=5, so 10^5=100000-1 = 99999.

No thats not i want

i want :
the largest palindrome made from the product of two 3-digit numbers.


\
So the answer to this would be : 906609.

i Hope you all understand
+Pie Number of slices to send: Send
Take what JD told you to heart. There is no need to shout with large print, and you definitely told us the wrong requirement in your first post.

My suggestion is you need these three keys: ctrl A delete. Then you start with a sheet of paper and you work out what you are going to do. I suggest you start by working out how you can tell that an integer is palindromic. Leave everything else out, get that working, and only then consider any of the other features.
+Pie Number of slices to send: Send
 

DharmiL Sanghvi wrote:
i m trying to find out the largest 3 digit Palindrome number.

The answer of this is :
906609
Thats it i m just trying to find out this number.




I guess 906609 is a six digit number ... which doesn't answers your question that you want to find out largest 3 digit palindrome.

+Pie Number of slices to send: Send

Lalit Mehra wrote:

DharmiL Sanghvi wrote:
i m trying to find out the largest 3 digit Palindrome number.

The answer of this is :
906609
Thats it i m just trying to find out this number.




I guess 906609 is a six digit number ... which doesn't answers your question that you want to find out largest 3 digit palindrome.



Yea i m sorry i wasnt able to properly explain what i wanted.

its :
the largest palindrome made from the product of two 3-digit numbers
+Pie Number of slices to send: Send

Campbell Ritchie wrote:Take what JD told you to heart. There is no need to shout with large print, and you definitely told us the wrong requirement in your first post.

My suggestion is you need these three keys: ctrl A delete. Then you start with a sheet of paper and you work out what you are going to do. I suggest you start by working out how you can tell that an integer is palindromic. Leave everything else out, get that working, and only then consider any of the other features.



Yea i am sorry it was my mistake.

working out how you can tell that an integer is palindromic


i started working out that way, but coudnt figure out what to do.
So did it this way
+Pie Number of slices to send: Send
Well, I think you have done it the wrong way. Whenever I see code that complicated, I think there must be something wrong with it, even without reading it. And thinkyou are going to end up deleting the lot.
If you can’t work out how to tell whether a number is palindromic, try turning it into a String and working out whether that is palindromic. If you search these fora, you will find a few posts every year about how to check palindromes. You should, however, write down how you intend to work out palindromicity on paper first.
Then you can create methods to test that. Get them working and only then consider the rest of the task.

Hint: I remember a recursive solution appearing here once. It is nice and elegant.

By the way: where is this question from? It looks like something they ask inProject Euler.
+Pie Number of slices to send: Send

Campbell Ritchie wrote:Well, I think you have done it the wrong way. Whenever I see code that complicated, I think there must be something wrong with it, even without reading it. And thinkyou are going to end up deleting the lot.
If you can’t work out how to tell whether a number is palindromic, try turning it into a String and working out whether that is palindromic. If you search these fora, you will find a few posts every year about how to check palindromes. You should, however, write down how you intend to work out palindromicity on paper first.
Then you can create methods to test that. Get them working and only then consider the rest of the task.

Hint: I remember a recursive solution appearing here once. It is nice and elegant.

By the way: where is this question from? It looks like something they ask inProject Euler.



YeP
you are right ht equestion is from Porject Euler, but i solved the question.
i Gave them the right answer, then i m asking you people so as to do the programm more efficiently & to learn something in future
+Pie Number of slices to send: Send
The whole point of project euler is not to come up with the right answer, but to figure out the algorithm. Start very simple:

1) generated every possible 6 digit number
2) Test a number to see if it meets the conditions.

Note how the two are 100% independent of each other...I don't care how I got a number, but assuming I have one, I can test it. and generating all the six digit numbers doesn't care what I do with them.

So once you have that, you look at how you would do one part: Assuming you have a number, how do you test it to see if it meets your conditions? well...it has to be a palindrome, and it has to be the product of two three-digit number.

Now you know you have to do two things: 1) is the number a palindrome, and 2) is it the product of two three-digit number. Note that each of THESE are independent of each other. So, figure out how to do ONE Of those two things...

keep breaking down hte problem into component parts, and only work on one at a time.
+Pie Number of slices to send: Send
Hi everyone,

I have been trying to figure this palindrome out, however no clue. Since I am at the third chapter of the book Introduction to Java programming 10th edition I have not come across the loops yet not even to how to break down the
three digit integer into three integers.

I need to write program that prompts user to enter a three-digit integer and determines whether it is a palindrome number or not.

I have been doing a bit of a searching and finally got to information how to reverse the number. There is however something wrong since if I enter the
3 digit integer which is palindrome, result is ("not a palindrome");

thanks for the assistance.

best regards

+Pie Number of slices to send: Send
 

Lovro Bajc wrote:I have been doing a bit of a searching and finally got to information how to reverse the number


No you didn't. That code will not reverse the number.
Try printing out the values of rev, rmd and num after each step and see what their values are.
+Pie Number of slices to send: Send
 

Lovro Bajc wrote:I have been trying to figure this palindrome out, however no clue. Since I am at the third chapter of the book Introduction to Java programming 10th edition I have not come across the loops yet not even to how to break down the three digit integer into three integers.


Then, I hate to say, but you're a few weeks away from a solution yet.

I need to write program that prompts user to enter a three-digit integer and determines whether it is a palindrome number or not.


Then have you considered writing a program that works out whether the String they entered is a palindrome or not?

After all:
If the String they entered is a valid number.
AND
The String they entered is a palindrome.

Doesn't that make the number palinodromic? (Maybe not; but I suspect so)

So, you now have TWO problems:
  • Is the string they entered a number?
  • Is it a palindrome?

  • And (believe me) tryng to work out whether a String is a palindrome is much easier than trying to work out whether the number it represents is.

    Winston
    Pay attention! Tiny ad!
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 5507 times.
    Similar Threads
    *Stateless* methods vs. functions
    [Easy] Palindromes
    Palindrome
    Palindrome
    display number xxx as "x x x " method
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 03:06:36.