edi02
asked on
string to BigInteger array
I have a string (contents) wich is a concatation of numbers (129012002150...) and I use every group of 3 to load a BigInteger array with them:
BigInteger[] B_array;
Int i;
i = 0;
for (int x=0; x < contents.length()-3; x+=3)
{
B_array[i] = BigInteger.valueOf(content s.substrin g(x,x+3))) ;
i = i +1;
}
and it doesn't work. I want to have in my B_array something like:
129
12
2
150
.
.
BigInteger[] B_array;
Int i;
i = 0;
for (int x=0; x < contents.length()-3; x+=3)
{
B_array[i] = BigInteger.valueOf(content
i = i +1;
}
and it doesn't work. I want to have in my B_array something like:
129
12
2
150
.
.
BigInteger.valueOf() doesn't take a String
Try
B_array[i] = new BigInteger(contents.substr ing(x,x+3) );
B_array[i] = new BigInteger(contents.substr
This works:
String contents = "129012002150";
BigInteger[] B_array = new BigInteger[contents.length ()/3]; // <<<<< have to new these ones
int i = 0;
for (int x=0; x <= contents.length()-3; x+=3) { // x <= instead of x <
B_array[i] = new BigInteger(contents.substr ing(x,x+3) );
i++;
}
String contents = "129012002150";
BigInteger[] B_array = new BigInteger[contents.length
int i = 0;
for (int x=0; x <= contents.length()-3; x+=3) { // x <= instead of x <
B_array[i] = new BigInteger(contents.substr
i++;
}
Add
for (int j=0; j<B_array.length; j++)
System.out.println( ((BigInteger)B_array[j]).f loatValue( ));
To check the result
for (int j=0; j<B_array.length; j++)
System.out.println( ((BigInteger)B_array[j]).f
To check the result
ASKER
thanx
You're welcome.
Kindly close this Q if you feel like your problem is solved.
Kindly close this Q if you feel like your problem is solved.
ASKER
May i ask u one more question ...
How do you transform from Integer to BigInteger?
How do you transform from Integer to BigInteger?
Integer i = new Integer(2000);
BigInteger b = new BigInteger("" + i);
BigInteger b = new BigInteger("" + i);
Or
BigInteger b = BigInteger.valueOf(i.intVa lue());
BigInteger b = BigInteger.valueOf(i.intVa
ASKER
I tried that and got this error:
C:\Second\second.java:167: int cannot be dereferenced
p_calc[indic] = BigInteger.valueOf(p_found .intValue( ));
Were i have at the start:
private static BigInteger[] p_calc = new BigInteger[100];
C:\Second\second.java:167:
p_calc[indic] = BigInteger.valueOf(p_found
Were i have at the start:
private static BigInteger[] p_calc = new BigInteger[100];
ASKER
This worked:
p_calc[indic] = new BigInteger("" + p_found);
p_calc[indic] = new BigInteger("" + p_found);
>> int cannot be dereferenced
if p_found is an int then that should have been
p_calc[indic] = BigInteger.valueOf(p_found );
The one you wrote would work id p_found was an Integer
if p_found is an int then that should have been
p_calc[indic] = BigInteger.valueOf(p_found
The one you wrote would work id p_found was an Integer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ahh hopefully the last one ... :-)
Trying to convert a String to a Char. I know exactly my Strings are all between 0 and 255. So im sure they will have each of them a Char representation.
Trying to convert a String to a Char. I know exactly my Strings are all between 0 and 255. So im sure they will have each of them a Char representation.
Do you mean a String that contains from "0" to "255" ?
>> String to Char
You mean Character of char?
String s = "123";
char c = (char) Integer.parseInt(s);
>> String to Char
You mean Character of char?
String s = "123";
char c = (char) Integer.parseInt(s);
Since you posted another Q for that last question, please close this one.
can this code help u out.
String myStr = "ThisData";
Char[] myChar = new Char[myStr.getLength()];
for(int i = 0; i < myStr.getLenght(); i++)
myChar[i] = myStr.charAt(i);
Bye
Naeem Shehzad Ghuman
String myStr = "ThisData";
Char[] myChar = new Char[myStr.getLength()];
for(int i = 0; i < myStr.getLenght(); i++)
myChar[i] = myStr.charAt(i);
Bye
Naeem Shehzad Ghuman
Thanks.
(Better accept the real "answer" as answer for the people that read it afterwards)
(Better accept the real "answer" as answer for the people that read it afterwards)