High, Low number checker in Java

High, Low number checker in Java
  • Version
  • Download 51
  • File Size 3.77 KB
  • Create Date May 12, 2016

High, Low number checker in Java

This sample java program will determine the highest and the lowest number entered by the user. The program will ask the user to enter 3 numbers and the program will display which is the highest and lowest among them. It is also coded in gui and console version.

Source code:

import javax.swing.*;
class HighLowNumberCheckerGUI {
public static void main(String[] args) {
String input1, input2, input3;	
double num1=0, num2=0, num3=0, high=0, low=5;
String cont="n";

do
{
input1 = JOptionPane.showInputDialog(null,"enter first number: ");
num1=Double.parseDouble(input1);

input2 = JOptionPane.showInputDialog(null,"enter second number: ");
num2=Double.parseDouble(input2);

input3 = JOptionPane.showInputDialog(null,"enter third number: ");
num3=Double.parseDouble(input3);

if (num1 <= num2 && num1 <= num3){
	low=num1;
	}
else if (num2 <= num1 && num2 <= num3){
	low=num2;
	}
else if	(num3 <= num1 && num3 <= num2){ low=num3; } if (num1 >= num2 && num1 >= num3){
	high=num1;
	}
else if (num2 >= num1 && num2 >= num3){
	high=num2;
	}
else if	(num3 >= num1 && num3 >= num2){
	high=num3;
	}
	
JOptionPane.showMessageDialog(null,"Highest number: " + high  + "
" + "Lowest number: "+ low );
			

	cont = JOptionPane.showInputDialog(null,"Continue? y or n ");
	}while (cont.matches("y"));
	JOptionPane.showMessageDialog(null,"Program Closing");

}
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.