Question

Write a java program making use of methods that finds the smallest of any three numbers...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import javax.swing.*;

public class FindSmallest {

    public static int smallest(int n1, int n2, int n3) {
        int min = n1;
        if (n2 < min) min = n2;
        if (n3 < min) min = n3;
        return min;
    }

    public static void printSmallest(int min) {
        JOptionPane.showMessageDialog(null, "Smallest number is " + min);
    }

    public static void main(String[] args) {
        int n1 = Integer.parseInt(JOptionPane.showInputDialog("Enter first number"));
        int n2 = Integer.parseInt(JOptionPane.showInputDialog("Enter first number"));
        int n3 = Integer.parseInt(JOptionPane.showInputDialog("Enter first number"));
        
        int min = smallest(n1, n2, n3);
        printSmallest(min);
    }
}
Add a comment
Know the answer?
Add Answer to:
Write a java program making use of methods that finds the smallest of any three numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT