Hi everyone! Question??? I have created a source code for converting Decimal numbers to Binary. I haven't done this in a while so I need a litte help on figuring out what is wrong with my code. The problem is I enter the JOptionPane class in order to prompt the user for input and display message but when I do, my source code no longer prints out correctly or excepts the source code. Any Help on this?
Thanks in Advance IT's :)
Below is the code I have created:
import java.io.*;
import java.util.*;
import java.lang.*;
import javax.swing.JOptionPane;
public class Mirage'
{
public static void main (String args[])throws IOException
{
int a=1;
while(a==1)
{
String str,str1;
JOptionPane.showInputDialog("Please Enter Decimal to be converted to Binary:");
InputStreamReader sr=new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(sr);
str=br.readLine();
int x=Integer.parseInt(str);
int y[] = new int[50];
int i=0;
if (x/2!=0 || x==1)
{
while(x!=1)
{
y[i]=x%2;
x=x/2;
i++;
}
y[i]=1;
}
JOptionPane.showMessageDialog(" + 's binary representation is:");
for(int z=i;z>=0;z--)
{
System.out.println(y[z]);
}
JOptionPane.showInputDialog("Enter 1 for enter another value 0 or other value for exit:");
str1=br.readLine();
int b=Integer.parseInt(str1);
if(b==1)
a=1;
else
a=0;}
}
}