这是我正在做的一个项目。请参阅此Imgur链接以查看说明。
https://i.stack.imgur.com/d64zW.png
I have this to work too from but it doesn't seem to be helping me much
这是我正在做的一个寻找两个集合的交集的实验室。我已经尝试了我能想象到的一切。这是我的代码。我认为我的主要问题是:将下面的行数保存为整数,并将字符串数组转换为整数数组,然后将其添加到集合中。
import java.io.IOException;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.util.*;
public class intersectionRunner {
public static void main(String args[]) throws IOException
{
Scanner in = new Scanner(new File("intersection.dat"));
int numberOfProjects = Integer.parseInt(in.nextLine()); //proven to be =3
int numLinesBelow=0;
for(int i=0; i<numberOfProjects; i++) {
//proven to run 3 times
Set<Integer> intersection = new TreeSet<Integer>();
if(in.nextLine().length()==1) {
numLinesBelow=in.nextLine();
System.out.println(numLinesBelow);
}
for(int j =0; j< 0; j++) {
}
}
//MAIN ENDS
}
//CLASS ENDS
}现在我的输出是:Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from String to int at intersectionRunner.main(intersectionRunner.java:18)
老实说,这是一场灾难。我被吓坏了,因为我已经尝试了我能想到的一切,但一切都以错误告终。明天就要交了
输入文件如下所示
3
1 2 3 4 5 5
3 4 5 6 7 5
4 5 1 2 3 5 6 7 8 9
5
10 11 15 61 42 14 112 34
12 13 11 61 42 10 34 12 14 112
10 10 13 11 112 54 61 13 13 34
11 112 15 42 13 34 17 10
71 10 11 112 75 63 15 42 34 56 67
4
1 2
3 4 5
6 7 8 9
10 11 12 13 14发布于 2020-10-14 20:48:51
为了解决这个问题,请不要
numLinesBelow=in.nextLine();使用
numLinesBelow=in.nextInt();或者在检查后将字符串解析为int
https://stackoverflow.com/questions/64236280
复制相似问题