Make a program that prints out the binary representation of an integer. Does not have to deal with negatives. I will post my way of solving this in a week, maybe sooner. Oh and no it's not a homework assignment of mine!
import javax.swing.*;
public class DecToBin{
public static void main(String [] args){
int numDec=0
String numBin="";
numDec=Integer.parseInt(JOptionPane.showInputDialog("Enter a number:"));
while(numDec>=1)
{
if(numDec==1){
numBin="1"+numBin; break;
}
else{
if(numDec%2==0)
{ numBin="0"+numBin;numDec/=2;}
else
{ numBin="1"+numBin;numDec/=2;}
}
}
JOptionPane.showMessageDialog(null,"Binary Number:"+numBin);
System.exit(0);
}
}
//i hope that this will work ^_^