Home LearnJava program that prompts the user to input two integer values and outputs the largest and smallest numbers

Java program that prompts the user to input two integer values and outputs the largest and smallest numbers

by Buhle Dlamini
Write a complete Java program that prompts the user to input two integer values and outputs the largest and smallest numbers.
Spread the love

Write a complete Java program that prompts the user to input two integer values and outputs the
largest and smallest numbers.

The program includes JOptionPane for both the input and output statements.


import javax.swing.JOptionPane;

/**
 *
 * @author layla
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      
        int num1 ; 
        int num2 ;
        
        int bignum = 0; 
        int smallnum = 0;
        
       num1 = Integer.parseInt(JOptionPane.showInputDialog("Enter First Number"));
       
       num2 = Integer.parseInt(JOptionPane.showInputDialog("Enter Second Number"));
       
       if(num1 > num2 ){
           bignum = num1;
           
       }
       else {
           
         smallnum  = num1;
           
       }
       
       if (num2 > num1){
           bignum = num2 ;
           
           
       }else {
           smallnum = num2; 
       }
                
        JOptionPane.showMessageDialog(null,bignum );
        JOptionPane.showMessageDialog(null,smallnum);
        
    }
    
}
https://www.youtube.com/watch?v=hNp0LY-dJzQ

How to create a user with sudo privileges in Kali Linux 2020

Related Articles

1 comment

How to Switch on Facebook Automatic member Approval | Googleboy news 06/03/2021 - 5:44 am

[…] Java program that prompts the user to input two integer values and outputs the largest and smallest … […]

Leave a Comment