Hi I want to know what's the problem with my code. I'm just a beginner. I'm trying to display the smallest number, but everytime I run the program, the output is always equal to zero. However if I use this code to find the largest number, wherein the boolean condition in if statement is (number>=largest), it works. But if I change it to (number<=smallest) to find the smallest number, it does not work.
Here's my code:
import javax.swing.*;
public class HighestNum {
public static void main (String args[])
{
int value = 0,number=0,smallest = 0;
while (value<10)
{
value++;
number = Integer.parseInt(JOptionPane.showInputDialog("Enter a number "+value+":"));
}
if (number <= smallest)
smallest=number;
else
smallest = smallest;
String msg="The smallest number is :"+smallest;
JOptionPane.showMessageDialog(null,msg);
}
}