Skip to content

Latest commit

 

History

History
executable file
·
23 lines (17 loc) · 1.18 KB

f79b.md

File metadata and controls

executable file
·
23 lines (17 loc) · 1.18 KB

Back to questions

f79b: Perfect palindromic cubes

A number x is a perfect palindromic cube if it is a perfect cube (i.e., x=y3 for some integer y), and it is a palindrome when written in decimal (i.e., it appears the same backwards). For example, 1030301 is a perfect palindromic cube: it is clearly a palindrome, and 1013 = 1030301.

Write a program that enumerates the first 1500 non-negative integers, and indicates which integers yield palindromic numbers when they are cubed. The output of your program should begin:

0 cubed is 0
1 cubed is 1
2 cubed is 8
7 cubed is 343

Think about whether or not your program would work properly if you continued significantly larger non-negative integers. If it would not, why not?

Hints: You may find the length and charAt methods of the String class useful. These are instance methods: you invoke them on a String object. Also, you may find the String.valueOf method helpful to turn an int into a String. This is a class method (also called a global method or static method): you invoke it independently of a String object. See the Java documentation for more details.