Моя программа должна получать от пользователя 2 набора чисел, находить пересечение и разницу между двумя наборами, а затем спрашивать пользователя, хочет ли он или она снова воспроизвести его. У меня возникла проблема с попыткой снова запустить мою программу, и я не могу понять, почему все, что я знаю, это то, что я продолжаю получать «синтаксическую ошибку на токене», «удалить этот токен», и я не знаю почему я продолжаю получать эту ошибку, пожалуйста, помогите.Java игра снова и еще ошибка?
import java.util.*;
public class Sets { private static final int MAXSIZE = 20;// the maximum size of the array is 20 static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
int[] resultSet = new int[MAXSIZE];
int[] setA = new int[MAXSIZE];
int y=0;
System.out.print("How many numbers will be in the first set? ");
int sizeA = keyboard.nextInt();//enter the numbers for the first set
while (sizeA < 1 || sizeA > MAXSIZE) {//a number larger than 20 can't be entered
System.out.print("Size is not valid, please try again: ");
sizeA = keyboard.nextInt();
}
getData(setA, sizeA);
sort(setA,sizeA);
printData(setA,sizeA);
int[] setB = new int[MAXSIZE];
System.out.print("How many numbers will be in the second set? ");
int sizeB = keyboard.nextInt();//enter the numbers for the second set
while (sizeB < 1 || sizeB > MAXSIZE) {
System.out.print("Size is not valid, please try again: ");
sizeB = keyboard.nextInt();
}
getData(setB, sizeB);//go to get getData method
sort(setB,sizeB);
System.out.println("The intersection is: ");
int temp = intersection(setA,sizeA,setB,sizeB,resultSet);
printData(resultSet, temp);
System.out.println("The difference is: ");
temp = difference(setA,sizeA,setB,sizeB,resultSet);
printData(resultSet, temp);
System.out.println("Do you want to repeat the program again with two different sets (y or n)?");
int playAgain = keyboard.nextInt();
if ("y" != null)
main(args);
}
else{
break;
}
public static void getData(int[] set, int size) {
// This method will retrieve "size" number of unique integers from the
// keyboard.
// The integers will be placed into the array set.
int temp, uniqueNum = 0;
while (uniqueNum < size) {
boolean flag = true;
temp = keyboard.nextInt();
for (int i = 0; i < uniqueNum; i++) {
if (temp == set[i]) {
flag = false;
break;
}
}
if (flag) {
set[uniqueNum] = temp;
uniqueNum++;
}
}
}
public static int intersection(int[] setA, int sizeA, int[] setB,
int sizeB, int[] resultSet) {
// This method will calculate the intersection of sets A and B.
int found = 0;
for (int x = 0; x < sizeA; x++) {
for (int y = 0; y < sizeB; y++) {
if (setA[x] == setB[y]) {
resultSet[found] = setA[x];
found++;
break;
}
}
}
return found;
}
public static int difference(int[] setA, int sizeA, int[] setB, int sizeB,
int[] resultSet) {
// This method will calculate the difference (A-B) of the two sets.
int found = 0;
for (int x = 0; x < sizeA; x++) {
boolean flag = true;
for (int y = 0; y < sizeB; y++) {
if (setA[x] == setB[y]) {
flag = false;
break;
}
}
if (flag) {
resultSet[found] = setA[x];
found++;
}
}
return found;
}
public static void sort(int[] nums, int size) {
// This method will sort the elements in the nums array into ascending
// order.
for (int count = 0; count < size; count++) {
int integer = count;
int B = nums[count];
while ((integer > 0) && (nums[integer - 1] > B)) {
nums[integer] = nums[integer - 1];
integer--;
}
nums[integer] = B;
}
}
public static void printData(int[] set, int size) {
for (int i = 0; i < size; i++)
System.out.print(set[i] + " ");
System.out.println("");
}
}
Пожалуйста, избегайте использования переполнения стека в качестве отладочного источника толпы. –