Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>your if statement is jacked up:</p> <pre><code>if(Verzameling.a.elementen[i] = Verzameling.b.elementen[j]) </code></pre> <p>you are doing assignment, you are not testing anything.</p> <p>try</p> <pre><code>Verzameling.a.elementen[i].equals(Verzameling.b.elementen[j]) </code></pre> <p>or </p> <pre><code>Verzameling.a.elementen[i] == Verzameling.b.elementen[j] </code></pre> <p>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)</p> <p>PREEDIT --</p> <p>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.</p> <p>EDIT -- I can't believe Im doing someone's homework, but -- this does not work, but at least it compiles</p> <pre><code>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 &lt; 100; i++) { elementen[i] = i; } Random random1 = new Random(seed); for (int i = 0; i &lt; 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 &lt; aantal; i++) { System.out.print(elementen[i] + " "); } System.out.println(); } static boolean deelverzamelingVan() { for (int i = 0; i &lt; aantal2; i++) { for (int j = 0; j &lt; 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; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload