Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java calculator joptionpane

import java.util.Scanner;
import javax.swing.JOptionPane;
 
public class Calculator
{
    public static void main(String [] args)
    {
        Scanner norbel = new Scanner(System.in);
 
        int answer;
 
        String FNumber = JOptionPane.showInputDialog("Enter first Integer: ");
        int fnum = Integer.parseInt(FNumber);
        fnum = norbel.nextInt();     
        String operator = JOptionPane.showInputDialog("Operation:
 1.Addition
 2.Subtraction
 3.Multiplication
 4.Division
");
        Integer opt = Integer.parseInt(operator);
 
 
        if(opt == 1)
        {
            String opt1 = JOptionPane.showInputDialog("Enter second Integer: ");
            int snum = Integer.parseInt(opt1);
            snum = norbel.nextInt();
            answer = fnum + snum;
            String ans = "Answer" +answer+ "!";
            JOptionPane.showMessageDialog(null,answer);
 
        if(opt == 2)
        {
            String opt2 = JOptionPane.showInputDialog("Enter second Integer: ");
            int snum = Integer.parseInt(opt2);
            snum = norbel.nextInt();
            answer = fnum -  snum;
            String ans = "Answer" +answer+ "!";
            JOptionPane.showMessageDialog(null,ans);
        }
        if(opt == 3)
        {
            String opt3 = JOptionPane.showInputDialog("Enter second Integer: ");
            int snum = Integer.parseInt(opt3);
            snum = norbel.nextInt();
            answer = fnum * snum;
            String ans = "Answer" +answer+ "!";
            JOptionPane.showMessageDialog(null,ans);
        }
        if(opt == 4)
        {
            String opt4 = JOptionPane.showInputDialog("Enter second Integer: ");
            int snum = Integer.parseInt(opt4);
            snum = norbel.nextInt();
            answer = fnum / snum;
            String ans = "Answer" +answer+ "!";
            JOptionPane.showMessageDialog(null,ans);
        }
        else
        {
            String error = "Error";
            JOptionPane.showMessageDialog(null, error);
        }
 
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: sending file over socket stream 
Java :: android how to change focus on confirm button on keyboard 
Java :: zebra zpl print java 
Java :: Not allowed to bind to service Intent 
Java :: actionevent java swing 
Java :: java backtracking 
Java :: consumer 
Java :: spring down load 
Java :: java create a random number 
Java :: best wireless headphoenes under 200 
Java :: java coding standards for constants 
Java :: java interview question answer 
Java :: how to create gravity in Java 
Java :: java was started but returned exit code=13 
Java :: get string match percentage java 
Java :: How tomake teris in Java 
Java :: Java Maven Using platform encoding (UTF-8 actually) to read mojo metadata, i.e. build is platform dependent! 
Java :: Java Using noneOf(Size) 
Java :: java switch case enum 
Java :: 3x+1 in java 
Java :: java assert keyword 
Java :: The create method: 
Java :: java.lang.nullpointerexception (no error message) 
Java :: java new.JFrame(); 
Java :: javafx check if enter pressed 
Java :: Calling constructor methods in java 
Java :: Join Two Java Strings 
Java :: SpringBootStarter maven dependency 
Java :: springboot body 
Java :: concatenar java 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =