繁体   English   中英

无法解析方法append(int)

[英]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 ,可以使用addaddLast

另外,请避免使用raw type ,而应使用LinkedList<Integer>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM