Vorlesung 4 / Aufgabe 6
This commit is contained in:
parent
7e87a3bec2
commit
01bb3e9def
@ -1,78 +0,0 @@
|
||||
class Aufgabe {
|
||||
public static void main(String[] args) {
|
||||
enum Monate {Januar, Februar, März, April, Mai, Juni, Juli, August, September, Oktober, November, Dezember};
|
||||
String quartal = "";
|
||||
Monate monat = Monate.Oktober;
|
||||
|
||||
// Ursprüngliche switch-Anweisung:
|
||||
switch(monat) {
|
||||
case Januar : quartal = "1. Quartal"; break;
|
||||
case Februar : quartal = "1. Quartal"; break;
|
||||
case März : quartal = "1. Quartal"; break;
|
||||
case April : quartal = "2. Quartal"; break;
|
||||
case Mai : quartal = "2. Quartal"; break;
|
||||
case Juni : quartal = "2. Quartal"; break;
|
||||
case Juli : quartal = "3. Quartal"; break;
|
||||
case August : quartal = "3. Quartal"; break;
|
||||
case September : quartal = "3. Quartal"; break;
|
||||
case Oktober : quartal = "4. Quartal"; break;
|
||||
case November : quartal = "4. Quartal"; break;
|
||||
case Dezember : quartal = "4. Quartal"; break;
|
||||
default : quartal = "";
|
||||
}
|
||||
|
||||
System.out.println("a.) ursprüngliche switch-Anweisung: " + quartal);
|
||||
|
||||
// Zusammenfassung mehrerer Ausdrücke.
|
||||
switch(monat) {
|
||||
case Januar, Februar, März : quartal = "1. Quartal"; break;
|
||||
case April, Mai, Juni : quartal = "2. Quartal"; break;
|
||||
case Juli, August, September : quartal = "3. Quartal"; break;
|
||||
case Oktober, November, Dezember : quartal = "4. Quartal"; break;
|
||||
default : quartal = "";
|
||||
}
|
||||
|
||||
System.out.println("b.) Zusammenfassung mehrerer Ausdrücke: " + quartal);
|
||||
|
||||
// Pfeilnotation
|
||||
switch (monat) {
|
||||
case Januar -> quartal = "1. Quartal";
|
||||
case Februar -> quartal = "1. Quartal";
|
||||
case März -> quartal = "1. Quartal";
|
||||
case April -> quartal = "2. Quartal";
|
||||
case Mai -> quartal = "2. Quartal";
|
||||
case Juni -> quartal = "2. Quartal";
|
||||
case Juli -> quartal = "3. Quartal";
|
||||
case August -> quartal = "3. Quartal";
|
||||
case September -> quartal = "3. Quartal";
|
||||
case Oktober -> quartal = "4. Quartal";
|
||||
case November -> quartal = "4. Quartal";
|
||||
case Dezember -> quartal = "4. Quartal";
|
||||
default -> quartal = "";
|
||||
}
|
||||
|
||||
System.out.println("c.) Pfeilnotation: " + quartal);
|
||||
|
||||
// Zusammenfassung mehrerer Ausdrücke in Pfeilnotation.
|
||||
switch(monat) {
|
||||
case Januar, Februar, März -> quartal = "1. Quartal";
|
||||
case April, Mai, Juni -> quartal = "2. Quartal";
|
||||
case Juli, August, September -> quartal = "3. Quartal";
|
||||
case Oktober, November, Dezember -> quartal = "4. Quartal";
|
||||
default -> quartal = "";
|
||||
}
|
||||
|
||||
System.out.println("d.) Zusammenfassung mehrerer Ausdrücke in Pfeilnotation: " + quartal);
|
||||
|
||||
// switch-Ausdruck mit Pfeilnotation
|
||||
quartal = switch(monat) {
|
||||
case Januar, Februar, März -> "1. Quartal";
|
||||
case April, Mai, Juni -> "2. Quartal";
|
||||
case Juli, August, September -> "3. Quartal";
|
||||
case Oktober, November, Dezember -> "4. Quartal";
|
||||
default -> "";
|
||||
};
|
||||
|
||||
System.out.println("e.) switch-Ausdruck mit Pfeilnotation: " + quartal);
|
||||
}
|
||||
}
|
129
VL04/Aufgabe06/Aufgabe06.java
Normal file
129
VL04/Aufgabe06/Aufgabe06.java
Normal file
@ -0,0 +1,129 @@
|
||||
package VL04.Aufgabe06;
|
||||
|
||||
/**
|
||||
* Vorlesung 4 / Aufgabe 6
|
||||
*
|
||||
* @author Sebastian Brosch
|
||||
*/
|
||||
public class Aufgabe06 {
|
||||
public static void main(String[] args) {
|
||||
enum Months {
|
||||
January,
|
||||
February,
|
||||
March,
|
||||
April,
|
||||
May,
|
||||
June,
|
||||
July,
|
||||
August,
|
||||
September,
|
||||
October,
|
||||
November,
|
||||
December
|
||||
};
|
||||
String quarter = "";
|
||||
Months month = Months.October;
|
||||
|
||||
System.out.printf("Monat: %s\n\n", month);
|
||||
|
||||
switch (month) {
|
||||
case January:
|
||||
quarter = "1. Quartal";
|
||||
break;
|
||||
case February:
|
||||
quarter = "1. Quartal";
|
||||
break;
|
||||
case March:
|
||||
quarter = "1. Quartal";
|
||||
break;
|
||||
case April:
|
||||
quarter = "2. Quartal";
|
||||
break;
|
||||
case May:
|
||||
quarter = "2. Quartal";
|
||||
break;
|
||||
case June:
|
||||
quarter = "2. Quartal";
|
||||
break;
|
||||
case July:
|
||||
quarter = "3. Quartal";
|
||||
break;
|
||||
case August:
|
||||
quarter = "3. Quartal";
|
||||
break;
|
||||
case September:
|
||||
quarter = "3. Quartal";
|
||||
break;
|
||||
case October:
|
||||
quarter = "4. Quartal";
|
||||
break;
|
||||
case November:
|
||||
quarter = "4. Quartal";
|
||||
break;
|
||||
case December:
|
||||
quarter = "4. Quartal";
|
||||
break;
|
||||
default:
|
||||
quarter = "";
|
||||
}
|
||||
|
||||
System.out.printf("a.) ursprüngliche switch-Anweisung: %s\n", quarter);
|
||||
|
||||
switch (month) {
|
||||
case January, February, March:
|
||||
quarter = "1. Quartal";
|
||||
break;
|
||||
case April, May, June:
|
||||
quarter = "2. Quartal";
|
||||
break;
|
||||
case July, August, September:
|
||||
quarter = "3. Quartal";
|
||||
break;
|
||||
case October, November, December:
|
||||
quarter = "4. Quartal";
|
||||
break;
|
||||
default:
|
||||
quarter = "";
|
||||
}
|
||||
|
||||
System.out.printf("b.) Zusammenfassung mehrerer Ausdrücke: %s\n", quarter);
|
||||
|
||||
switch (month) {
|
||||
case January -> quarter = "1. Quartal";
|
||||
case February -> quarter = "1. Quartal";
|
||||
case March -> quarter = "1. Quartal";
|
||||
case April -> quarter = "2. Quartal";
|
||||
case May -> quarter = "2. Quartal";
|
||||
case June -> quarter = "2. Quartal";
|
||||
case July -> quarter = "3. Quartal";
|
||||
case August -> quarter = "3. Quartal";
|
||||
case September -> quarter = "3. Quartal";
|
||||
case October -> quarter = "4. Quartal";
|
||||
case November -> quarter = "4. Quartal";
|
||||
case December -> quarter = "4. Quartal";
|
||||
default -> quarter = "";
|
||||
}
|
||||
|
||||
System.out.printf("c.) Pfeilnotation: %s\n", quarter);
|
||||
|
||||
switch (month) {
|
||||
case January, February, March -> quarter = "1. Quartal";
|
||||
case April, May, June -> quarter = "2. Quartal";
|
||||
case July, August, September -> quarter = "3. Quartal";
|
||||
case October, November, December -> quarter = "4. Quartal";
|
||||
default -> quarter = "";
|
||||
}
|
||||
|
||||
System.out.printf("d.) Zusammenfassung mehrerer Ausdrücke in Pfeilnotation: %s\n", quarter);
|
||||
|
||||
quarter = switch (month) {
|
||||
case January, February, March -> "1. Quartal";
|
||||
case April, May, June -> "2. Quartal";
|
||||
case July, August, September -> "3. Quartal";
|
||||
case October, November, December -> "4. Quartal";
|
||||
default -> "";
|
||||
};
|
||||
|
||||
System.out.printf("e.) switch-Ausdruck mit Pfeilnotation: %s\n", quarter);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user