当前位置: 代码迷 >> Java相关 >> 小问题,可就是不明白,呵呵,菜鸟不要见怪啊。
  详细解决方案

小问题,可就是不明白,呵呵,菜鸟不要见怪啊。

热度:317   发布时间:2010-11-24 17:34:09.0
小问题,可就是不明白,呵呵,菜鸟不要见怪啊。
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Test_ extends JFrame{
     public static void main(String arg[]){
         Test B=new Test();
         B.Fn();
         
     }
     void Fn(){
         String str=JOptionPane.showInputDialog("请输入你的成绩:");
         int a=Integer.parseInt(str);

         if (a>=60&&a<80)
              JOptionPane.showMessageDialog(this,"恭喜你及格了!,继续加油!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if (a>=80&&a<100);
          JOptionPane.showMessageDialog(this,"very good!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if (a<60&&a>40||a==40)
             JOptionPane.showMessageDialog(this,"you need to study hard!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if(a<40||a==40)
             JOptionPane.showMessageDialog(this,"hope you to have a good attitude","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if(a>100)
             JOptionPane.showMessageDialog(this,"error","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         
     }     
         

}



当我输入12时,它为什么还会弹出very good 啊?
搜索更多相关的解决方案: void  100  public  import  

----------------解决方案--------------------------------------------------------
你把Fn()里的代码换成下面的代码试试:
程序代码:
void Fn(){
         String str=JOptionPane.showInputDialog("请输入你的成绩:");
         int a=Integer.parseInt(str);

         if (a>=60&&a<80)//我只改了判断条件,
              JOptionPane.showMessageDialog(this,"恭喜你及格了!,继续加油!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if (a>=80&&a<=100);
          JOptionPane.showMessageDialog(this,"very good!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if (a<60&&a>=40)
             JOptionPane.showMessageDialog(this,"you need to study hard!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if(a<40&&a>=0)
             JOptionPane.showMessageDialog(this,"hope you to have a good attitude","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if(a>100||a<0)
             JOptionPane.showMessageDialog(this,"error","成绩情况",JOptionPane.INFORMATION_MESSAGE);
        
     }     

我只改了判断条件

----------------解决方案--------------------------------------------------------
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Test_ extends JFrame{//应该是Test吧??
     public static void main(String arg[]){
         Test B=new Test();
         B.Fn();
         
     }
     void Fn(){
         String str=JOptionPane.showInputDialog("请输入你的成绩:");
         int a=Integer.parseInt(str);
         if (a>=60&&a<80)
              JOptionPane.showMessageDialog(this,"恭喜你及格了!,继续加油!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if (a>=80&&a<100);//多加了一小分号
          JOptionPane.showMessageDialog(this,"very good!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if (a<60&&a>40||a==40)
             JOptionPane.showMessageDialog(this,"you need to study hard!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if(a<40||a==40)
             JOptionPane.showMessageDialog(this,"hope you to have a good attitude","成绩情况",JOptionPane.INFORMATION_MESSAGE);
         if(a>100)
             JOptionPane.showMessageDialog(this,"error","成绩情况",JOptionPane.INFORMATION_MESSAGE);         
     }            
}
//以下我的建议,请见谅哦哦
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Test extends JFrame{
     public static void main(String arg[]){
         Test B=new Test();
         B.Fn();
         
     }
     void Fn(){
         String str=JOptionPane.showInputDialog("请输入你的成绩:");
         int a=Integer.parseInt(str);

         if (a>=60&&a<80){
            JOptionPane.showMessageDialog(this,"恭喜你及格了!,继续加油!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
            }
         else if (a>=80&&a<100){
        JOptionPane.showMessageDialog(this,"very good!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
        }
         else if (a<60&&a>40){
           JOptionPane.showMessageDialog(this,"you need to study hard!","成绩情况",JOptionPane.INFORMATION_MESSAGE);
           }
         else if(a<=40&&a>=0){
           JOptionPane.showMessageDialog(this,"hope you to have a good attitude","成绩情况",JOptionPane.INFORMATION_MESSAGE);
           }
         else{
           JOptionPane.showMessageDialog(this,"error","成绩情况",JOptionPane.INFORMATION_MESSAGE);
           }
         
     }
----------------解决方案--------------------------------------------------------
  相关解决方案