Write a java application that accepts two values from the keyboard using input dialog box,theprogram should compute the same of the numbers and display the results on a message dialogbox.
Question
Write a java application that accepts two values from the keyboard using input dialog box,theprogram should compute the same of the numbers and display the results on a message dialogbox.
Solution
Here is a simple Java application that does what you asked for. It uses JOptionPane for the input and output dialog boxes.
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
// Get the first number
String firstNumberString = JOptionPane.showInputDialog("Enter the first number");
int firstNumber = Integer.parseInt(firstNumberString);
// Get the second number
String secondNumberString = JOptionPane.showInputDialog("Enter the second number");
int secondNumber = Integer.parseInt(secondNumberString);
// Compute the sum
int sum = firstNumber + secondNumber;
// Display the result
JOptionPane.showMessageDialog(null, "The sum of the numbers is " + sum);
}
}
This program works as follows:
- It shows an input dialog box asking for the first number. The entered value is stored as a string.
- It converts the string to an integer.
- It does the same for the second number.
- It computes the sum of the two numbers.
- It shows a message dialog box displaying the sum.
Similar Questions
Write a program that reads in a number (integer) as input, adds 1 to it, and then prints out the result. Here is an example interaction between your program and the user:Please enter a number: 34
Identify the valid sequence of statements to read integer data from the keyboard.*1 pointimport java.util.Scanner;int num = scan.nextInt();Scanner scan = new Scanner(System.in);Scanner scan = new Scanner(System.in); import java.util.Scanner; int num = scan.nextInt();import java.util.Scanner; Scanner scan = new Scanner(System.in); int num = scan.nextInt();Scanner scan = new Scanner(System.in); int num = scan.nextInt(); import java.util.Scanner;
Write code that ask the user to enter two numbers. Use for loop to display all numbers between the two numbers including the two numbers with the double of each number as shown in the examples.Use the following code at the beginning of your answer:print("Enter first number:")num1=int(input())print("Enter second number:")num2=int(input())print()For example:Test Input Result115Enter first number:Enter second number:1 22 43 64 85 10Answer:(penalty regime: 0 %)
in java Arun needs to create a program that handles user input by converting a float value to both double and integer formats. Write a program for him that reads a float value entered by the user, converts it to double with one decimal place and integer type, and displays the results. Input format : The input consists of a float value f. Output format : The output prints the converted double value, rounded off to one decimal place, followed by the converted integer. Separate the values using (;).
Create a mini calculator application, which has following functionalitiesAdditionSubtractionDivisionMultiplicationYour app should haveTwo input boxes which should take two numbers from the user.Four Buttons with following text contentAddSubtractDivideMultiplyWhen user enter 2 and 4 and clicks on multiply button, an alert should come with 8 as ansWhen user enter 8 and 4 and clicks on Divide button,an alert should come with 2 as ans
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.