[英]Cannot resolve method append(int)
該項目的目標是創建一個計算器,使用戶可以選擇要使用的操作,然后將其求解並添加到鏈接列表中。 最后一個選擇是查看歷史記錄,這些記錄是過去的答案或解決方案。
我很新,這是我真正想自己完成的項目,但是我已經研究了,但仍然不太了解如何解決。 請向我解釋,以便我更好地理解! 還請評論我的代碼的設計或流程。 謝謝!
import java.util.Scanner;
import java.util.LinkedList;
public class projectOne {
public static void main(String[] args) {
int one = 0;
int two = 0;
int ans = 0;
int selection = 0;
Scanner scanner = new Scanner(System.in);
LinkedList l = new LinkedList();
do{
System.out.println("\nSelect an option: \n1. Addition \n2. Subtraction \n3. Multiplication \n4.Division \n5. See History");
selection = scanner.nextInt();
/* if (selection >= 1 && selection <= 4) {
System.out.println("\nEnter two numbers to be used in relevant calculation: ");
one = scanner.nextDouble();
two = scanner.nextDouble();
}
*/
switch(selection) {
case 1:
System.out.println("Performing Addition. \nEnter first number: ");
one = scanner.nextInt();
System.out.println("Enter second number: ");
two = scanner.nextInt();
System.out.println(one + " + " + two + " = " + (one + two));
ans = one + two;
l.append(ans);
break;
case 2:
System.out.println("Performing Subtraction. \nEnter first number: ");
one = scanner.nextInt();
System.out.println("Enter second number: ");
two = scanner.nextInt();
System.out.println(one + " - " + two + " = " + (one - two));
ans = one - two;
l.append(ans);
break;
case 3:
System.out.println("Performing Multiplication. \nEnter first number: ");
one = scanner.nextInt();
System.out.println("Enter second number: ");
two = scanner.nextInt();
System.out.println(one + " * " + two + " = " + (one * two));
ans = one * two;
l.append(ans);
break;
case 4:
System.out.println("Performing Division. \nEnter first number: ");
one = scanner.nextInt();
System.out.println("Enter second number: ");
two = scanner.nextInt();
System.out.println(one + " / " + two + " = " + (one / two));
ans = one / two;
l.append(ans);
break;
case 5:
System.out.println("History: \n" + l);
break;
}
} while(selection != 6);
}
}
LinkedList
沒有方法append
,可以使用add
, addLast
。
另外,請避免使用raw type
,而應使用LinkedList<Integer>
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.