Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3335566
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:01:59+00:00 2026-05-18T00:01:59+00:00

I have to make an array of 100 numbers and then shuffle the first

  • 0

I have to make an array of 100 numbers and then shuffle the first 20 randomly to have 2 different arrays; A and B.

For this assignment I have to check wether the first 20 numbers from Array A are a subset of the first 20 numbers af Array B

Up until now I have this:

import java.util.Random;

public class opgave6 {
 public static void main(String[] args){

  Verzameling a = new Verzameling(20, 3);
  Verzameling b = new Verzameling(20, 4);

  System.out.println(Verzameling.deelverzamelingVan());
 }
}



class Verzameling {
 int[] elementen;
 int elementen2;
 static int aantal2;

 Verzameling(int aantal , int seed) {
  elementen = new int[100];
  int aantal2 = aantal;

  for(int i = 0; i < 100; i++){
   elementen[i] = i;
  }

  Random random1 = new Random(seed);

  for(int i = 0; i < 100; i++){
   int r = random1.nextInt(100);
   int temp;
   temp = elementen[i];
   elementen[i] = elementen[r];
   elementen[r] = temp;
  } 

  printVerzameling(aantal);


 }

 Verzameling(int seed) {

 }

 void printVerzameling(int aantal){
  for (int i = 0; i < aantal; i++){
   System.out.print(elementen[i] + " ");
  } 
  System.out.println();
 }

 static boolean deelverzamelingVan() {
  while (true) {
   for(i = 0; i < aantal2; i++){
    for(j = 0; j < aantal2; j++){
     if(Verzameling.a.elementen[i] = Verzameling.b.elementen[j])
     break;
    }
   }

  } 
 }


}

However, it doesnt work at all because I cannot figure out how to compare the elementen[i] from object A to element[j] from object B. How can i compare the different elements from both objects by using the static method in the same class.

(So Verzameling A and B are both instances of the Verzameling class, with a static method to check if A is subset of B. How can I get the numbers in the array from Verzameling A and B?)

If something is not clear please let me know! I don’t need whole solutions, just how I can access the value of elementen[i] from object A and B. thanks!

EDIT:

this is the problem line:

if(Verzameling.a.elementen[i] == Verzameling.b.elementen[j])

thanks for the comment, however it is still erroring when i compile. It says it cannot find symbol about verzameling.a.elementen, i, verzameling.b.elementen and j. I think i am naming it wrong, is it ok to call the variable by saying: classname.objectname.variable of object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:01:59+00:00Added an answer on May 18, 2026 at 12:01 am

    your if statement is jacked up:

    if(Verzameling.a.elementen[i] = Verzameling.b.elementen[j])
    

    you are doing assignment, you are not testing anything.

    try

    Verzameling.a.elementen[i].equals(Verzameling.b.elementen[j])
    

    or

    Verzameling.a.elementen[i] == Verzameling.b.elementen[j]
    

    note that you will need to make sure Verzameling.a.elementen[i] is not null if you use the equals method. Also note that for numbers == is ok, but for objects you want to use equals unless you are sure you want == (== means something very specific for objects)

    PREEDIT —

    Your code is not compiling for a few reasons. The first of which is that your a and b variables are declared in the scope of main, so they are only accessible in main. Moving them up to the class and making them public and static means they can be accessed from anywhere.

    EDIT — I can’t believe Im doing someone’s homework, but — this does not work, but at least it compiles

    import java.util.Random;
    
    public class opgave6 {
        public static Verzameling a = new Verzameling(20, 3);
        public static Verzameling b = new Verzameling(20, 4);
    
        public static void main(String[] args) {
            System.out.println("before something");
            System.out.println(Verzameling.deelverzamelingVan());
            System.out.println("after something");
        }
    }
    
    
    class Verzameling {
        int[] elementen;
        int elementen2;
        static int aantal2;
    
        Verzameling(int aantal, int seed) {
            elementen = new int[100];
            int aantal2 = aantal;
    
            for (int i = 0; i < 100; i++) {
                elementen[i] = i;
            }
    
            Random random1 = new Random(seed);
    
            for (int i = 0; i < 100; i++) {
                int r = random1.nextInt(100);
                int temp;
                temp = elementen[i];
                elementen[i] = elementen[r];
                elementen[r] = temp;
            }
    
            printVerzameling(aantal);
        }
    
        // you arent using it -- do so or delete it
        Verzameling(int seed) {
        }
    
        void printVerzameling(int aantal) {
            for (int i = 0; i < aantal; i++) {
                System.out.print(elementen[i] + " ");
            }
            System.out.println();
        }
    
        static boolean deelverzamelingVan() {
            for (int i = 0; i < aantal2; i++) {
                for (int j = 0; j < aantal2; j++) {
                    int aElementen = opgave6.a.elementen[i];
                    int bElementen = opgave6.b.elementen[j];
                    System.out.println(String.format("Comparing a[i] to b[i] [%d, %d]", aElementen, bElementen));
                    if (aElementen == bElementen)
                        break;
                }
            }
    
            // need to return something, i dont know what.
            return true;
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string. I then split the string to make an array. I use
Hi I need to make an dynamic array like this: I have a max
Suppose i have 100 instances of a class. I want to make arrays of
For development of web services, i have to make multilevel Associative array as follows
I have an array of raw sound data samples, and I'm trying to make
Let's say I have this $(document).ready(function() { var array = $.makeArray($('p')); $(array).appendTo(document.body); }); });
Using this sample : I have make my own Fragment that holds tabhost and
So I have to create three random numbers using the Math.random(); method then use
I am attempting to make a program that will input numbers into an array
First sorry if I should have added this to my earlier question today ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.