if i have this code so i want to check if the user enters a valid binary no or any other no , so how?
import javax.swing.*;
public class lily {
static public void main (String args [] ){
String word;
String second;
word = JOptionPane.showInputDialog(null, "enter your first number ");
double star = Double.parseDouble(word);
double finish =Integer.parseInt(word,2) ;
second = JOptionPane.showInputDialog(null, "enter your second number ");
double sun = Double.parseDouble(second);
double wild =Integer.parseInt(second,2) ;
double planet=finish+wild;
word=Integer.toBinaryString((int)Math.round(planet));
JOptionPane.showMessageDialog(null, "the result of the two numbers" + word);
JOptionPane.showMessageDialog(null, "the result of the two numbers" + planet);
System.exit(0);
}
}
2007-10-18
23:46:47
·
2 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design