Saturday, June 9, 2012

Day 28 , 9 june 2012



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

 
;