变量尚未初始化

时间:2019-03-16 16:04:08

标签: java variables joptionpane

  

每当我尝试编译时,都会遇到engmark,mathmark的错误   并且所有这些字符串变量都尚未初始化。

 import javax.swing.JOptionPane;


 class grade{ 
           public static void main(String[] args){

         String engmark;

         String mathmark;

         String sstmark;

         String scimark;

         String compmark;

在此行中,发生错误

      float totmark=Float.parseFloat(engmark)+Float.parseFloat(mathmark)+   
               Float.parseFloat(sstmark)+Float.parseFloat(scimark)+
                Float.parseFloat(compmark);

         String response;


          response= JOptionPane.showInputDialog("Enter the maximum marks of each subject : ");

                 if (response==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (response.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }

                          else

                        engmark= JOptionPane.showInputDialog(null,"Enter the marks obtained in english :");

                                        if (engmark==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (engmark.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }
                                else           
                                 mathmark= JOptionPane.showInputDialog(null,"Enter the marks obtained in mathematics :");
                                        if (mathmark==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (mathmark.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }

                                else                                    
                                scimark= JOptionPane.showInputDialog(null,"Enter the marks obtained in science :");
                                        if (scimark==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (scimark.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }

                                else                                    
                                sstmark= JOptionPane.showInputDialog(null,"Enter the marks obtained in S.st. :");
                                        if (sstmark==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (sstmark.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }

                                else                                    
                                compmark= JOptionPane.showInputDialog(null,"Enter the marks obtained in computer :");
                                        if (compmark==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (compmark.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }



                     else

                     JOptionPane.showMessageDialog(null,"Your total marks is :" + totmark);                          

}

如果我需要进行一些修改,请告诉我。我对java很陌生,也许这只是一个简单的错误,但是如果您的帮助我将不胜感激。

}

0 个答案:

没有答案