binary conversion 3

Okay so I have fought through this program that is supposed to take a binary number and convert it to a integer (decimal number) I got it to work, and everything works great my only question now is...

I want it to display the results say in a dialog box as follows

13

1

0

1

1

I am able to get it to display in the console like this but not in a dialog box

Here is my code, any help would be appreciated

import javax.swing.JOptionPane;

publicclass binaryconverter{

publicstaticvoid main(String[] args){

String binum_st;

int binum , newnum, pickednum1 ,pickednum2 ,pickednum3 ,pickednum4 ,pickednum5 ,pickednum6 =0,pickednum7 ,pickednum8,dec;

binum_st= JOptionPane.showInputDialog(null,"Enter first number");

binum = Integer.parseInt(binum_st);

newnum = binum;

pickednum8 = newnum % 10;

dec = pickednum8 * 1;

newnum = newnum / 10;

pickednum7 = newnum % 10;

dec = (pickednum7 * 2) + dec;

newnum = newnum /10;

pickednum6 = newnum % 10;

dec = (pickednum6 * 4) + dec;

newnum = newnum /10;

pickednum5 = newnum % 10;

dec = (pickednum5 * 8) + dec;

newnum = newnum /10;

pickednum4 = newnum % 10;

dec = (pickednum4 * 16) + dec;

newnum = newnum /10;

pickednum3 = newnum % 10;

dec = (pickednum3 * 32) + dec;

newnum = newnum /10;

pickednum2 = newnum % 10;

dec = (pickednum2 * 64) + dec;

newnum = newnum /10;

pickednum1 = newnum % 10;

dec = (pickednum1 * 128 ) + dec;

System.out.println(dec);

if (pickednum1 == 1)

System.out.println(pickednum1);

if ((pickednum2 == 0) && (pickednum1 ==0))

;

else

System.out.println(pickednum2);

if ((pickednum3 == 0 )&&(pickednum2==0))

;

else

System.out.println(pickednum3);

if ((pickednum4==0 )&& (pickednum3 ==0))

;

else

System.out.println(pickednum4);

if ((pickednum5==0 )&& (pickednum4 ==0))

;

else

System.out.println(pickednum5);

if ((pickednum6==0 )&& (pickednum5 ==0))

;

else

System.out.println(pickednum6);

if ((pickednum7==0 )&& (pickednum6 ==0))

;

else

System.out.println(pickednum7);

if (pickednum8!=0)

System.out.println(pickednum8);

}

}

[3281 byte] By [joshuapbella] at [2007-11-27 8:35:11]
# 1
Instead of all the System.out.println, build a String like this:"13\n1\n1\n\0\n1\n"Now display it in a JOptionPane.
baftosa at 2007-7-12 20:31:37 > top of Java-index,Java Essentials,Java Programming...
# 2

Reposted from http://forum.java.sun.com/thread.jspa?threadID=5187303&messageID=9731638#9731638.

Why? given that you got an answer there. You also got several wrong answers, in fact the thread had perhaps the highest concentration of wrong answers in a short thread I've ever seen, but there was certainly one correct answer.

ejpa at 2007-7-12 20:31:37 > top of Java-index,Java Essentials,Java Programming...
# 3

> Reposted from

> http://forum.java.sun.com/thread.jspa?threadID=5187303

> &messageID=9731638#9731638.

>

> Why? given that you got an answer there. You also got

> several wrong answers, in fact the thread had perhaps

> the highest concentration of wrong answers in a short

> thread I've ever seen, but there was certainly one

> correct answer.

But the question is now different, it is console vs. dialog output.

So I think my answer stands.

baftosa at 2007-7-12 20:31:37 > top of Java-index,Java Essentials,Java Programming...
# 4
haha very funny, but it doesn't convert anything like the OP asked for. Neither did most of the 'answers' in the other thread but that's no excuse.And of course I was addressing myself to the OP.
ejpa at 2007-7-12 20:31:37 > top of Java-index,Java Essentials,Java Programming...