2017-03-18 20 views
-7

我收到此錯誤信息說標識符預計Java - 錯誤:<identifier>預計,如何解決它?

newIntArray3 = addValues(StackA.pop(), StackB.pop()); 

有人可以幫助我嗎?
我想用字符逐字符添加兩個數字,並使用彈出的堆棧顯示答案。

import java.util.*; 

public class sandy { 
    public static void main(String[] args){ 
     int[] newIntArray1 = new int[]{5,9,2}; 
     int[] newIntArray2 = new int[]{4,7,5,6}; 

     Stack StackA = new Stack(); 
     Stack StackB = new Stack(); 
     Stack StackC = new Stack(); 

     StackA.push(newIntArray1[0]); 
     StackA.push(newIntArray1[1]); 
     StackA.push(newIntArray1[2]); 
     StackB.push(newIntArray1[0]); 
     StackB.push(newIntArray1[1]); 
     StackB.push(newIntArray1[2]); 
     StackB.push(newIntArray1[3]); 

     while (!StackA.empty() && !StackB.empty()) { 
      int[] newIntArray3 = new int[4]; 
      @SuppressWarnings("unchecked") 
      newIntArray3 = addValues(StackA.pop(), StackB.pop()); 
      int i=0;  
      while (i<=3); 
      StackC.push(newIntArray3); 
      i++; 
     } 

     System.out.println("result: " + StackC.pop() + StackC.pop() + StackC.pop() + StackC.pop()); 
    } 

    public void addValues() { 
     int x , y = 0; 
     int addValues = 0; 
     addValues = x+y; 
     System.out.println(addValues); 
    } 
} 
+0

'java的!= javascript' –

+0

爲什麼標記爲'javascript'? – abhishekkannojia

+2

'while(i <= 3);'我看到一個無限循環。請正確發佈您的代碼。 – abhishekkannojia

回答

1

此方法不採取任何參數,也可以返回類型缺失

public void addValues() { 

加入這一行就是採用這種方法,請

newIntArray3 = addValues(StackA.pop(), StackB.pop()); 
+0

請這個問題在你的代碼,並再次檢查 –

+0

即使我改變這個問題不會解決 –

+0

發佈更新的源代碼 –