2013-12-04 6 views
-2

У меня возникли проблемы с получением цикла for в моей программе для wrok. Я не уверен, что я делаю неправильно. Я работаю над ним около 3 часов и до сих пор не знаю, что делать.Для цикла: мой цикл цикла не выполняется должным образом

Я исправил заявление while. Это не проблема. Проблема заключается в том, что цикл for находится в нижней части кода.

Вот мой код:

while(!(strSelection=("5"))) 
    { 
     strSelection=JOptionPane.showInputDialog(
                null, "~~Please make a selection from the menu below~~"+ 
                "\n\n1. Add a new advisee"+ 
                "\n2. Update and advisee's information"+ 
                "\n3. Display all advisees"+ 
                "\n4. Display advisees who are cleared to graduate"+ 
                "\n5. Exit"+ 
                "\n\nWhat is your selection?", "Menu", 3); 

     switch(strSelection) 
     { 
      case "1": 

       String strString; 
       String strHours; 
       int iHours; 
       String strMajor; 
       boolean blnMajor; 
       String strIntent; 
       boolean blnIntent; 

       adv[iCount]=new Advisee(); 
       adv[iCount].setName(JOptionPane.showInputDialog(null,"What is the advisee's name?","Name",3)); 
       adv[iCount].setID(JOptionPane.showInputDialog(null,"What is the advisee's ID?","ID",3)); 
       adv[iCount].setConcentration(JOptionPane.showInputDialog(null,"What is the advisee's concentration?","Concentration",3)); 
       adv[iCount].setAdvisor(strAdvisor); 
       strHours=JOptionPane.showInputDialog(null,"What are the advisee's completed hours?","Completed Hours",3); 
       iHours=Integer.parseInt(strHours); 
       adv[iCount].setHoursCompleted(iHours); 
       strMajor=JOptionPane.showInputDialog(null,"Does the advisee have the major sheet?","Major Sheet",3); 
       blnMajor=Boolean.parseBoolean(strMajor); 
       adv[iCount].setMajorSheet(blnMajor); 
       strIntent=JOptionPane.showInputDialog(null,"Does the advisee have the intent to graduate form filed?","Intent To Graduate",3); 
       blnIntent=Boolean.parseBoolean(strIntent); 
       adv[iCount].setIntentFiled(blnIntent); 
       iCount++; 
       iAccum++; 
       break; 

      case "2": 
       String strUpdateSelection; 
       String strOutput=""; 
       String strAccumulator=""; 
       System.out.print(iAccum); 
       for(iCount=0;iCount==iAccum;iCount++) 
       { 
        strOutput=adv[iCount].getName(); 
        strAccumulator+=strOutput; 
       } 

       strUpdateSelection=JOptionPane.showInputDialog(
                   null,"~~Please select which advisee's information you need to update~~"+ 
                   "\n"+strOutput+ 
                   "\nWhat is your selection?","Information Update",3); 

       break; 
      case "5": 
       System.exit(0); 
       break; 
     } 

    }           
} 
} 
+0

Советуйте только опубликовать код, который дает ошибки для всего. И будьте конкретны по поводу вашей ошибки :) –

+1

Что нужно сделать? – Shishigami

+0

Мне нужно, чтобы он прошел цикл и отобразил все пользовательские входы советника. – Treyeyeeyeeye

ответ

0

Изменение от

while(strSelection!="5") 

Для

while(!"5".equals(strSelection)) 
+0

Некоторые объяснения были бы хороши. – ApproachingDarknessFish

+0

@ValekHalfHeart В большинстве случаев вы не будете называть оператор «==» для сравнения строк, см. Здесь http://stackoverflow.com/questions/767372/java-string-equals-versus – gyorgyabraham

0

Вы сравниваете не-равенство в String. То, как вы должны сделать, это следующие

while(!"5".equals(strSelection)) 

Или

while(!strSelection.equals("5")) 

Не

while(strSelection!="5") 

И изменить ваш for петля

for(iCount=0;iCount<=iAccum;iCount++) 

вместо

for(iCount=0;iCount==iAccum;iCount++) 
+0

Я понимаю. Я исправил эту проблему в своем коде. Проблема, с которой я сейчас сталкиваюсь, связана с циклом for. – Treyeyeeyeeye

+0

@Treyeyeeyeeye исправить ваш цикл 'for' как мой ответ –

+0

Я сделал это изменение, и теперь он дает мне ошибку исключения указателя на нуль при компиляции. – Treyeyeeyeeye

Смежные вопросы