Hi!
> newbie question
> what i'm trying to do is manipulate a string from a GUI textfield. I want to
[quoted text clipped - 14 lines]
> i get errors like "can't resolve symbol " i've declared digit as an
> Integer.
You get these errors, because parseInt() requires a String as argument,
but charAt(i) returns a char. And the other problem is, that digit must
bedeclared as an int, because parseInt() returns an int.
But back to your problem.
You can solve it, by casting the return value of charAt(i) to int, like:
int digit = (int) charAt(i); But i don't know, whether this is the
preferred way, because the String will be converted to a character and
not to a byte or int...
The other way: int digit = Integer.parseInt(
enterNumber.getText().substring(0, 1) );
substring(0, 1) returns the String, that contains only "2",
substring(1, 2) will contain "3" ...
> i've also got errors "int cannot be dereferenced" when I tried some aother
> things
>
> any suggestions would be appreciated
Hope this helps...
willerubrneck - 10 Mar 2005 20:30 GMT
This seems to work but once I get to the end of string I get an "end of
index" error.
this what i'm trying to accomplish.
ex. 2010 base 3 = 57,
firstBase = Integer.parseInt(firstBaseTF.getText());
// equals 3
count =(enterNumberTF.getText().length());
// equals 4
do
{
digit = Integer.parseInt(enterNumberTF.getText().substring(i, i + 1));
// gets digit from string
newNumber = newNumber + (digit * (firstBase ^ (count - i))); //
converts number to base specifed
i++;
}
while(i <= count);
> Hi!
>
[quoted text clipped - 36 lines]
>
> Hope this helps...
Gordon Beaton - 11 Mar 2005 07:17 GMT
> this what i'm trying to accomplish.
> ex. 2010 base 3 = 57,
>
> firstBase = Integer.parseInt(firstBaseTF.getText());
First, realize that the base is simply a textual representation of the
given value. The value itself doesn't change, you don't a new int to
store a number in a different base.
Here's an extremely simple way to display the value in base 3:
System.out.println(Integer.toString(firstBase, 3));
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
willerubrneck - 11 Mar 2005 12:54 GMT
I got it to accomplish what I was trying to do, thanks everyone.
j = (count - 1);
do
{
digit = Integer.parseInt(enterNumberTF.getText().substring(i, i + 1));
newNumber = newNumber + (digit * (Math.pow(firstBase, j)));
i++;
j--;
}
while(i < count);
>> this what i'm trying to accomplish.
>> ex. 2010 base 3 = 57,
[quoted text clipped - 10 lines]
>
> /gordon