【发布时间】:2020-02-03 19:52:38
【问题描述】:
我正在尝试添加一个列表,以便在特定事件发生后打印一行文本。这是我在第 6 行遇到的错误。
错误:标记“
import java.util.Scanner;
public class RelativelyPrime {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
List<Integer> list = new ArrayList<>();
int num1 = scnr.nextInt();
int num2 = scnr.nextInt();
System.out.println("Common divisors of " + num1 + " and " + num2 + ":");
for(int i = 1; i<= Math.min(num1,num2); i++){
if(num1%i==0 && num2%i==0) {
System.out.println(i);
list.add(i);
}
}
if (list.size()<2){
System.out.print(num1 + " and " + num2 + " are relatively prime.");
}
else {
System.out.print(num1 + " and " + num2 + " are not relatively prime.");
}
}
}
【问题讨论】:
-
也许您还应该导入
List和ArrayList?您可能会更改为import java.util.*;。然后它对我有用,但我之前没有遇到同样的错误。你的版本是什么?这有帮助吗? -
我试过 import java.util.*;它仍然没有工作。我正在使用 drjava IDE。
-
IDE 应该没有那么重要。你的 java 版本是什么?试试
List<Integer> list = new ArrayList<Integer>();或许
标签: java list compiler-errors syntax-error