Here is the source code of Java applet I have written which compares 3 integer numbers and outputs the biggest and the smallest number….I wont explain the code…
import javax.swing.*;
import java.awt.Graphics;
public class ComparisionApplet extends JApplet{
String result;
String result1;
public void init()
{
int number1;
int number2;
int number3;
String numbera;
String numberb;
String numberc;
numbera = JOptionPane.showInputDialog("Enter first integer:");
numberb = JOptionPane.showInputDialog("Enter second integer:");
numberc = JOptionPane.showInputDialog("Enter third integer:");
number1 = Integer.parseInt(numbera);
number2 = Integer.parseInt(numberb);
number3 = Integer.parseInt(numberc);
if(number1 > number2)
if(number1 > number3)
{
result = number1 + " is the biggest number";
}
if(number2 > number1)
if(number2 > number3)
{
result = number2 + " is the biggest number";
}
if(number3 > number1)
if(number3 > number2)
{
result = number3 + " is the biggest number";
}
if(number1 < number2)
if(number1 < number3)
{
result1 = number1 + " is the smallest number";
}
if(number2 < number1)
if(number2 < number3)
{
result1 = number2 + " is the smallest number";
}
if(number3 < number1)
if(number3 < number2)
{
result1 = number3 + " is the smallest number";
}
}
public void paint(Graphics g)
{
super.paint(g);
g.drawString(result,25,70);
g.drawString(result1,25,100);
}
}