/**
* @(#)BCD.java
*
*
* @author
* @version 1.00 2009/3/5
*/
public class BCD {
public static void main (String args[]) {
{
String output = "";
String xn = javax.swing.JOptionPane.showInputDialog("Enter Number:");
int len = xn.length();
int pos = 0;
char a = xn.charAt(pos);
do{
a = xn.charAt(pos);
switch (a)
{
case '0':
output = "0000";
break;
case '1':
output = "0001";
break;
case '2':
output = "0010";
break;
case '3':
output = "0011";
break;
case '4':
output = "0100";
break;
case '5':
output = "0101";
break;
case '6':
output = "0110";
break;
case '7':
output = "0111";
break;
case '8':
output = "1000";
break;
case '9':
output = "1001";
break;
}
pos = 1 + pos;
} while (pos<len);
javax.swing.JOptionPane.showMessageDialog(null, "Number entered: "+xn+
"\n"+"Binary Encoded Decimal: "+output);
}
}
}
any help is greatly appreciated
thanks in advance

New Topic/Question
This topic is locked




MultiQuote






|