>Info zum Stichwort Java | >diskutieren | >Permalink 
hinkelchen schrieb am 8.12. 2000 um 14:58:19 Uhr über

Java

public class Sets_1 {

public static void main(String[] args) {

// Define three variables representing empty sets
int set1 = 0;
int set2 = 0;
int set3 = 0;

// Check if set1 is empty and print result
if (set1 == 0) System.out.println(»leer«);

// Insert element 15 into set1
set1 = set1 | (1<<15);

System.out.println (set1+» set1 15«);

// Insert element 5 into set1

set1 = set1 | (1<<5);

System.out.println (set1+» set1 5«);

// Check if set1 is empty and print result

if (set1 == 0) System.out.println(»leer«);
else System.out.println(»mindestens ein Element vorhanden«);

// Output the elements contained in set1
for (int i=0;i<32;i++){
int set1b;
set1b = set1;
set1b = set1 & (1<<i);
if (set1b != 0) System.out.println (i);
}

// Insert element 5 into set2
set2 = set2 | (1<<5);

// Insert element 8 into set2
set2 = set2 | (1<<8);

System.out.println (set2+» set2«);
System.out.println (set1+» set1«);

// Calculate set3 = union of set1 and set2
set3 = set1 | set2;

System.out.println (set3+» set3«);
// Output the elements contained in set3
for (int i=0;i<32;i++){
set3 = set3 & (1<<i);
if (set3 !=0) System.out.println(i);
}

// Calculate set3 = intersection of set1 and set2
set3 = set1 | set2;

// Output the elements contained in set3
for (int i=0;i<32;i++){
set3 = set3 & (1<<i);
if (set3 !=0) System.out.println(i);
}
// Calculate set3 = difference of set1 and set2 (i.e. set1 \ set2)
set3 = set1 ^ set2;

// Output the elements contained in set3
for (int i=0;i<32;i++){
set3 = set3 & (1<<i);
if (set3 !=0) System.out.println(i);
}
}
}







   User-Bewertung: +1
Oben steht ein nichtssagender, langweiliger Text? Bewerte ihn »nach unten«, wenn Du Bewertungspunkte hast. Wie geht das?.

Dein Name:
Deine Assoziationen zu »Java«:
Hier nichts eingeben, sonst wird der Text nicht gespeichert:
Hier das stehen lassen, sonst wird der Text nicht gespeichert:
 Konfiguration | Web-Blaster | Statistik | »Java« | Hilfe | Startseite 
0.0050 (0.0016, 0.0020) sek. –– 853806391