Ok I have a quick question. I am working on an assignment for class and one of the methods I am using is pretty simple. I am using JOptionPane to have a user input a positive value. What I am wondering is if there is a way to distinquish how many digits are in that number that can be known in the next method. I will outline that I am trying to do so that this might make sense:
First I will write a method that takes an integer number as input argument and returns the number of digits in that number.
Next I will write a method that takes an integer number and an integer array argument and fills the array with the appropriate digits of the number. So for example it would set intArray to the value 8, intArray to 7, ..., and intArray to 2.
Third I will write a boolean method that takes an integer array argument and returns the value true if the array is a palindrome else returns false.
Last I will write the main method that prompts the user repeatedly for an integer number, that uses the first method to find out the number of digits in that number, allocates the int array for that size, calls the second method to populate the array with the digits of the number, calls the third method to find out whether the array is a palindrome, and then prints out the result. The program will terminate when the user enters -99.
So ovbiously I do not know how to do all of this yet, but I am working on it. I was just wondering if anyone had any tips about the array and the first method in which I must find out how many digits the value is that the user entered. I think if I understood that I might understand the rest of the assignment a bit more. I feel a little overwhelmed and I promise I did not put all of this on here for someone to do it for me, I just thought it might help for you all to understand where my question was coming from. I appreciate it. Thanks!
The length of the string the user enters is a good starting point, but may give you funny answers. How many digits does "004" have? Since the question is about integers, the answer may be "1". How about "-5"? or "_2_" with blanks where I put underscores? If you want to get elaborate, you might:
Whew! Does that help?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Sep 08, 2004
ok reverting back above to the boolean expression. I am a little confused there....
If palindrome is usually used for letters and really is not supposed to be used for numbers i dont understand how it can be put into java. I mean how would there be a code for that? Can I use an if else statement that some how has the int Array = to the reverse of that int?? Little lost....any comments?