Create and populate the two sets of double values, in which the number of elements and the elements themselves are specified by the user. Iterate through the sets and compare the values.
For the purposes of this lab, we will say that the order matters in determining if the sets are the same.
If the arrays are the same in both length and values, print set one and set two are equal. Otherwise, print set one and set two are not equal. This is my code, but when I run it I get this message :
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at SetComparison.main(SetComparison.java:23)
I am new to coding, can anyone tell me what seems to be the problem?
import java.util.*;
import java.lang.*;
import java.io.*;
public class SetComparison
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scnr = new Scanner(System.in);
String str = scnr.nextLine();
String[] allNums = str.split("\\s+");
int array1Length = Integer.valueOf(allNums[0]);
int array2Length = Integer.valueOf(allNums[array1Length + 1]);
double array1[] = new double[array1Length];
double array2[] = new double[array2Length];
for (int i = 0; i < array1Length; i++) {
array1[i] = Double.valueOf(allNums[i + 1]);
}
for (int i = 0; i < array2Length; i++) {
array2[i] = Double.valueOf(allNums[array1Length + i + 2]);
}
if (Arrays.equals(array1, array2)) {
System.out.println("set one and set two are equal");
} else {
System.out.println("set one and set two are not equal");
}
}
}