gpt4 book ai didi

java - 无法解析方法append(int)

转载 作者:行者123 更新时间:2023-12-02 01:37:49 26 4
gpt4 key购买 nike

该项目的目标是创建一个计算器,让用户选择要使用的运算,然后将其求解并添加到链接列表中。最后一个选项是查看历史记录,即过去的答案或解决方案。

我很新,这是一个我真的想自己完成的项目,但我已经研究过了,但似乎仍然不太明白要解决什么或如何解决。请给我解释一下,以便我更好地理解!另请评论我的代码的设计或流程。谢谢!

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>相反。

关于java - 无法解析方法append(int),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54965617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com