//less than 10= "too cold", 10-20= "avarage", 21-30="hot",bigger than 30 ="Too Hot"
import javax.swing.JOptionPane;
public class TmaTwo
{
   public static void main(String[] args)
   {
      int number;
      int temp;
      String numString;
      numString =
          JOptionPane.showInputDialog
                 ("Enter temperature:");     
      number = Integer.parseInt(numString); 

            if (number < 10 )                
      JOptionPane.showMessageDialog(null,
                        "Too cold",
                         "Output",

       JOptionPane.INFORMATION_MESSAGE);       
     else if (number <21 ) 
       JOptionPane.showMessageDialog(null,
                        "Average",
                         "Output",


               JOptionPane.INFORMATION_MESSAGE);       
               else if (number > 20 ) 
       JOptionPane.showMessageDialog(null,
                        "Hot",
                         "Output",

       JOptionPane.INFORMATION_MESSAGE);    

              else if (number > 29 ) 
       JOptionPane.showMessageDialog(null,
                        "Too Hot",
                         "Output",
       JOptionPane.INFORMATION_MESSAGE);



      System.exit(0);
   }
}

im just a new student and tried to solve this problem, my problem here is the output for "too hot" when i key in 31 or bigger than 30 only hot appeared. so i need help

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You used swing classes. So the code should be on the EDT(Event Dispath Thread).
Try writing your code like this
e.g

public static void main(String[] args){
          EventQueue.invokeLater(new Runnable(){
                    public void run(){
                              // Write the Swing code here
                              //you wrote it in the main thread itself
                    }
         });
}

You used swing classes. So the code should be on the EDT(Event Dispath Thread).
Try writing your code like this
e.g

public static void main(String[] args){
          EventQueue.invokeLater(new Runnable(){
                    public void run(){
                              // Write the Swing code here
                              //you wrote it in the main thread itself
                    }
         });
}

Ignore this, this is not necessary at all ...

your problem is here:

else if (number > 20 )

since, 30 > 20, but the same applies to 31>20. what you want is:

else if (number < 31)

sorry guys.i'm not really understand the code but anyway thank you for tried 2 help me. i'm really appreciate . is it my code totally wrong command?? or any other method to solve this? sorry 4 lately respond. i thought when you all reply my thread it will inform me by an email.

sorry guys.i'm not really understand the code but anyway thank you for tried 2 help me. i'm really appreciate . is it my code totally wrong command?? or any other method to solve this? sorry 4 lately respond. i thought when you all reply my thread it will inform me by an email.

your code says:

if ( number > 20 )
perform a;
else {
if (number > 31 )
perform b;
}

no code will ever reach b, since: if number is NOT bigger than 20, it sure as hell will not be bigger than 31.
just look at my previous post, and make that change, that should solve your problem

This article has been dead for over six months. Start a new discussion instead.