Ask Question
16 December, 19:02

Write a java program making use of methods that finds the smallest of any three numbers that the user inputs. You must use JoptionPane to input the three numbers. A first method must be called and used to develop logic to find the smallest of the three numbers. A second method must be used to print out that smallest number found.

+1
Answers (1)
  1. 16 December, 19:14
    0
    import javax. swing. JOptionPane;

    public class num3 {

    public static void main (String[] args) {

    String val1 = JOptionPane. showInputDialog ("enter first number","value1");

    int num1 = Integer. parseInt (val1);

    String val2 = JOptionPane. showInputDialog ("enter second number","value2");

    int num2 = Integer. parseInt (val1);

    String val3 = JOptionPane. showInputDialog ("enter third number","value3");

    int num3 = Integer. parseInt (val1);

    //Calling findMin Method

    int minimum = findMin (num1, num2, num3);

    //Calling printMin to print the minimum

    printMin (minimum);

    }

    public static int findMin (int num1, int num2, int num3) {

    int min;

    if (num1
    min = num1;

    }

    else if (num2
    min = num2;

    }

    else{

    min = num3;

    }

    return min;

    }

    public static void printMin (int n) {

    JOptionPane. showMessageDialog (null, "The minimum is "+n);

    }

    }

    Explanation:

    Import javax. swing. javax. swing. JOptionPane; Use the input dialog method to receive three values convert these values to integers using the Integer. parseInt method Create the method findMin () which uses if and else statements to find the minimum of the three numbers Create method printMin which uses the showMessageDialog method to print the minimum value Call both methods in the main method
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a java program making use of methods that finds the smallest of any three numbers that the user inputs. You must use JoptionPane to ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers