# erase

• July 16th, 2011, 07:14 AM
Joy123
erase
Code :

```BigInteger PowerOfTwo = BigInteger.valueOf(2); DecimalToBinary = new BigInteger(LargeBase.getText()); String binaryString = DecimalToBinary.toString(2); int binaryNo = Integer.parseInt(binaryString, 2); String backTOString = Integer.toBinaryString(binaryNo); char[] binaryArray = backTOString.toCharArray(); int FristCount=0;int SecCount=0; for (char c : binaryArray){ if(c == 49){ // int i=c; will convter to ascii, so 1=49, 0=48.   display.setText(display.getText()+" "+PowerOfTwo+"^"+FristCount+" + ");} FristCount++; }```
this code is working, however the print out want to be 2+2.
However the print out come as 2+2+.
How to earse the last part of +
so come it will cone out like 2+2.
:confused:
• July 16th, 2011, 08:25 AM
dlorde
Re: erase
It might help if you explained what the code is supposed to be doing...
• July 16th, 2011, 09:22 AM
Norm
Re: erase
Code :

`display.setText(display.getText()+" "+PowerOfTwo+"^"+FristCount+" + ");}`
Is this the code that adds the ending +?
You need change the logic to put the + at the beginning of the concatenation vs at the end as you have here.
• July 16th, 2011, 05:13 PM
firebluetom
Re: erase
Your code will always print an extra " + ", you can't just erase it.
You can fix this by putting in an if() statement to check if there is more numbers to output.

if(c == 49){ // int i=c; will convter to ascii, so 1=49, 0=48.

display.setText(display.getText()+" "+PowerOfTwo+"^"+FristCount);
if( //more to print)
display(" + ");
}

FristCount++;
• July 16th, 2011, 05:55 PM
Norm
Re: erase
Why not use:
if(c == '1')
• July 17th, 2011, 05:11 AM
Joy123
Re: erase
Quote:

Originally Posted by Norm
Why not use:
if(c == '1')

c is char, when char convert to int. it will change to 49, when char is 1.
• July 17th, 2011, 05:15 AM
Joy123
Re: erase
Quote:

Originally Posted by firebluetom
Your code will always print an extra " + ", you can't just erase it.
You can fix this by putting in an if() statement to check if there is more numbers to output.

if(c == 49){ // int i=c; will convter to ascii, so 1=49, 0=48.

display.setText(display.getText()+" "+PowerOfTwo+"^"+FristCount);
if( //more to print)
display(" + ");
}

FristCount++;

how to use if statement to check?:confused: