Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help editing my code i keep getting the same error message import java.util

ID: 3820886 • Letter: N

Question

Need help editing my code i keep getting the same error message

import java.util.*;
import java.lang.*;
import java.io.*;

public class SetComparison
{
public static void main(String[] args)
{
int count = 0; //variable to manipulate while comparing arrays
Scanner con = new Scanner(System.in);
int array1size = 0;
int array2size = 0;
  
System.out.println("Enter the size of Array 1");
array1size = con.nextInt();
double[] arr1 =new double[array1size];
  
System.out.println("Enter the size of Array 2");
array2size = con.nextInt();
double[] arr2 =new double[array2size];
  
if (array1size == array2size)
{
System.out.println("Enter the values of Array 1");
  
for (int i=0;i<array1size;i++)
arr1[i]=con.nextDouble();
  
System.out.println("Enter the values of Array 2");
  
for (int i=0;i<array2size;i++)
arr2[i]=con.nextDouble();
  
for (int i=0;i<array2size;i++)
{
if((Math.abs(arr1[i]-arr2[i])>0.001)){
count++;
System.out.println("The values of arr1[" + i + "] and arr2[" + i + "] are not equal");
break;
}
}
  
if(count == 0){
System.out.println("set one and two are equal");
}else{
System.out.println("set one and two are not equal");
}
}
else
System.out.println("The Array sizes are not same ");
}
}

A5.12 Lab 5a Due 06-Apr-17 5.13 Lab 5b Due 11-Apr-17 Students This content is controlled by your instructor, and is not zyBooks content. Direct questions or concerns about this content to your instructor. If you have any technical issues with the zyLab submission system, use the "Trouble with lab?" button at the bottom of the lab Objectives In this lab you will practice using for loops with arrays and comparing double values, using a threshold, to see if two sets of numbers are the same Background Reading Zy Books Chapter 5 Task The first comment of your main method should be your identification comment: //Lab5b, Name mascID You will need to then: Create and populate the two sets of double values, in which the number of elements and the elements themselves are specified by the user. (i.e. the user will state how many numbers are in the first set, give the values for that set and then move on to the second set of numbers). 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. (HINT: This also means that the lengths of the arrays must be the same). 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 Comparing double values using a threshold Recall that floating-point numbers may differ in a very small value. For example, 1.0 might actually be stored as 0.9999999... or 1.0000000002. When comparing these values, we often use a "tolerance" level that says, "if the difference is smaller than some amount, then it is negligible and the numbers can be thought of as the same." We can achieve this by comparing the absolute value of the difference of the elements to the tolerance. For example if Math. abs arrayl [0 array2001 0.001 System. out.println ("The values of arrayl [01 and array 01 are not equal

Explanation / Answer

import java.util.*;

public class SetComparison {
public static void main(String[] args) {
int count = 0; // variable to manipulate while comparing arrays
Scanner con = new Scanner(System.in);
int array1size = 0;
int array2size = 0;

array1size = con.nextInt();
double[] arr1 = new double[array1size];
for (int i = 0; i < array1size; i++)
arr1[i] = con.nextDouble();
  
  
array2size = con.nextInt();
double[] arr2 = new double[array2size];
for (int i = 0; i < array2size; i++)
arr2[i] = con.nextDouble();
  
  
if (array1size == array2size) {
for (int i = 0; i < array2size; i++) {
if ((Math.abs(arr1[i] - arr2[i]) > 0.001)) {
count++;
break;
}
}

if (count == 0) {
System.out.println("set one and two are equal");
} else {
System.out.println("set one and two are not equal");
}
} else
System.out.println("The Array sizes are not same ");
con.close();
}
}

// Sample run

6
45.24 54.67 42.55 44.61 65.29 49.75
6
45.24 54.67 41.99 44.61 65.29 49.75
set one and two are not equal

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote