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 program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
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:...
Instructions: Create a Java program that reads a string entered by the user and then determines...
Instructions: Create a Java program that reads a string entered by the user and then determines and prints how many of each lowercase vowel (a, e, i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also, count and print the number of non-vowel characters. Example: User enters: "This house is beautiful." a: 1 e: 2 i: 3 o: 1 u: 2 non-vowel:10
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++ 
Code in Golang: Write a boolean function called share with one integer parameter which determines whether...
Code in Golang: Write a boolean function called share with one integer parameter which determines whether the sum of the digits in the inputted integer and the inputted integer share a factor other than one. If so, return true, otherwise return false. Examples: 121 sum is 4, so the function returns false 242 sum is 8, so the function returns true
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT