Assignment : Decimal to binary
import javax.swing.JOptionPane;
public class decimalToBinary {
public static void main(String[] args)
{
int number =
Integer.parseInt(JOptionPane.showInputDialog("Enter a number:
"));
String num="";
while(number != 0)
{
int res,temp;
temp = number;
res = number % 2;
number = temp / 2;
num = num + res;
}
for(int i=1;i<=num.length();i++)
{
System.out.print(num.charAt(num.length()-i));
}
}
}
0 comments:
Post a Comment