java - Basic Calculator -
im having problems program. programme displays first joption message dialog box, when input value, fails display sec dialog box??
import java.util.scanner; import javax.swing.joptionpane; public class javacalculator { public static void main(string[] args) { int num1; int num2; string operation; scanner input = new scanner(system.in); joptionpane.showinputdialog(null,"please come in first number"); num1 = input.nextint(); joptionpane.showinputdialog(null,"please come in sec number"); num2 = input.nextint(); joptionpane.showinputdialog(null,"please come in operation"); operation = input.next(); if (operation.equals ("+")) { joptionpane.showmessagedialog(null,"your reply is" + " " + (num1 + num2)); } if (operation.equals ("-")) { joptionpane.showmessagedialog(null,"your reply is" + " " + (num1 - num2)); } if (operation.equals ("/")) { joptionpane.showmessagedialog(null,"your reply is" + " " + (num1 / num2)); } if (operation.equals ("*")) { joptionpane.showmessagedialog(null,"your reply is" + " " + (num1 * num2)); } } }
read numbers dialog output instead of system.in:
string firstnumber = joptionpane.showinputdialog(null,"please come in first number"); if (firstnumber != null) { num1 = integer.parseint(firstnumber); }
scanner unnecessary in code.
java calculator
No comments:
Post a Comment