EqualityValues.java

1 minute read

This program was created in order to access Java’s GUI called JOptionPane. This GUI is heavily outdated as the UI is utter garbage (or rubbish).

The purpose of this program is to take user input of 3 numbers and accumulates duplicate values according to the 3 integers. parseInt is just to make sure that it takes the input as integers and the message dialog shows the result.

The code has been modified slightly and now uploaded to the site.

<— Return Home

Code Snippet

/*
Program Name: EqualityValues
Author: ENTPRESTIGIOUS
Date Finished: April 14, 2021
Compiler: JDK 11.0.10 LTS
Link: https://edabit.com/challenge/nfc7H9CQFqJp54uEh
*/
    
import javax.swing.JOptionPane;
public class EqualityValues {
    public static void main(String[] args){
        JOptionPane.showMessageDialog(null, "Welcome!\nPress enter to continue...");
        JOptionPane.showMessageDialog(null, "You will be asked to enter three numbers.\nPress enter to continue...");
        String input = JOptionPane.showInputDialog(null, "Please enter a number to return 3 integers of equal value");
        String input2 = JOptionPane.showInputDialog(null, "Please enter a number to return 3 integers of equal value");
        String input3 = JOptionPane.showInputDialog(null, "Please enter a number to return 3 integers of equal value");
        int firstNum = Integer.parseInt(input);
        int secondNum = Integer.parseInt(input2);
        int thirdNum = Integer.parseInt(input3);
        int result = equal(firstNum, secondNum, thirdNum);
        JOptionPane.showMessageDialog(null, "The answer is: " + result);
    }

    public static int equal(int a, int b, int c){
        int counter = 0;
        if (a == b || b == c || a == c){
            counter+= 2;
        }
        if (a == b && b == c && a == c){
            counter++;
        }
        // if (a == c){
        //     counter++;
        // }
        return counter;
    }
}

<— Return Home