Question

In: Computer Science

How to write a java application that reads an integer, then determines and display whether it's...

How to write a java application that reads an integer, then determines and display whether it's odd or even. Use the remainder operator.

Solutions

Expert Solution

import javax.swing.JOptionPane;

public class BasicGUI {

      public static void main(String[] args) {

            // TODO Auto-generated method stub

            //Showing the Welcome message in Dialog Box

            JOptionPane.showMessageDialog(null, "Welcome");

            //Asking the User to input a number

            String input = JOptionPane.showInputDialog("Enter a Number");

            //Converting the string version of number to Integer version

            int num = Integer.parseInt(input);

            //Showing the appropriate message for even or odd

            if(num%2==0){

                  JOptionPane.showMessageDialog(null, num+" is even number");

            }

            else{

                  JOptionPane.showMessageDialog(null, num+" is odd number");

            }

      }

}

Output


Related Solutions

(JAVA) Write an application that reads three nonzero values entered by the user and determines and...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Enter three sizes, separated by spaces(decimals values are acceptable): 4.5·5.5·3.5 A triangle could measure 4.50, 5.50, by 3.50.
Write a Java console application that reads a string for a date in the U.S. format...
Write a Java console application that reads a string for a date in the U.S. format MM/DD/YYYY and displays it in the European format DD.MM.YYYY  For example, if the input is 02/08/2017, your program should output 08.02.2017
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Write a Java program which reads a positive integer from the command line, then displays the...
Write a Java program which reads a positive integer from the command line, then displays the sum of all even values up to and including the value provided, followed by the sum of all odd values up to and including the value provided. validate that the command line argument is an integer greater than 0 to validate the type, you can use Integer.parseInt() with a try/catch for NumberFormatException use one or more for loops to perform the even and odd...
JAVA PROGRAMMING RecallNoIF! Write a program named RecallNoIF that reads an integer representing a year. (In...
JAVA PROGRAMMING RecallNoIF! Write a program named RecallNoIF that reads an integer representing a year. (In this case there is no prompt from the program.) The program prints out RECALL if the year was 2004, 2010 or 2015 and NO RECALL otherwise. CONSTRAINT: Nowhere in the program is an if statement used. REMINDER: the program's output is shown here in bold; the user's data entry is shown here in italics. Sample Interactive Run 1: 2010 RECALL Sample Interactive Run 2:...
Design and implement an application that reads an integer value and prints the sum of all...
Design and implement an application that reads an integer value and prints the sum of all even integers between 2 and the input value, inclusive. Print an error message if the input value is less than 2 and prompt accordingly so that the user can enter the right number. Your program file will be called YourLastNameExamQ2
Write a program that reads an integer, a list of words, and a character.
13.14 LAB: Contains the characterWrite a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character.Ex: If the input is:4 hello zoo sleep drizzle zthen the output is:zoo drizzleIn c++ 
Java Input, Output and for-loop function. Practice01) Write-an average SCORE application called TestScores01 This project reads...
Java Input, Output and for-loop function. Practice01) Write-an average SCORE application called TestScores01 This project reads in a list of integers as SCOREs, one per line, until a sentinel value of -1. After user type in -1, the application should print out how many SCOREs are typed in, what is the max SCORE, the 2nd max SCORE, and the min SCORE, the average SCORE after removing the max and min SCORE. When SCORE >= 90, the school will give this...
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
Develop a Java application that determines the gross pay for each of three employees.
(Salary Calculator) Develop a Java application that determines the gross pay for each of three employees. The company pays straight time for the first 40 hours worked by each employee and time and a half for all hours worked in excess of 40. You’re given a list of the employees, their number of hours worked last week and their hourly rates. Your program should input this information for each employee, then determine and display the employee’s gross pay. Use class...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT