How can i add output that warn user when they input non-number? (Means error when user input other than number as alphabet)
package decimal_binary; //use import javax.swing package when we use a gui import javax.swing.*; import java.util.Scanner; public class Decimal_Binary { public static void main(String[] args) { int n; String decNum; String binary; Scanner sc=new Scanner(System.in); { decNum = JOptionPane.showInputDialog(null, "Enter decimal number:"); n = Integer.parseInt(decNum); } if(n<0) { JOptionPane.showMessageDialog(null,"Invalid entry! Enter positive numbers only"); } else { binary = Integer.toBinaryString(n); JOptionPane.showMessageDialog(null, "Binary equivalent is: " +binary); } } }