Java - Einführung
Tag 1
Variables and Datatypes
Exercise 1.1 - Tell me about yourself
Declare variables to express your age, first name, gender, last name, birthday, average grade and whether you are married or not. Think which datatype is well suited for which variable.
Print all variables to the console with System.out.println
Exercise 1.2 - Simple Calculations
Declare two numeric variables with arbitary values. Calculate their sum, difference, product and quotient and print the calculation with the result on the console with System.out.println/System.out.printf. Perform all calculations with whole numbers and fractional numbers.
Bonus: Try to limit the decimal places of your calculations with the fractional numbers.
Your output should look like this:
138 + 235 = 373
138 - 235 = -97
Exercise 1.3 - Working with Strings [🤓 Advanced]
Create a variable of type String with “ Hello World! ” as its content (contains leading and trailing spaces).
- Print the String and its length to the console.
- Print the String with some variations:
- all letters in uppercase
- all letters in lowercase
- replace “World” with “Codersbay”
- without the leading spaces
- Repeat the printed String 15 times seperated with linebreaks (don't copy the code 15 times 😉)
You might find the official documentation of the String class helpful.
Tag 2
Zuweisungs- und logische Operatoren
Aufgabe 2.1 Eigenschaften einer Zahl
Schreibe ein Programm, dass von der Konsole eine Zahl einliest und ausgibt:
- ob es sich um eine runde Zahl handelt
- ob die Zahl gerade ist
- ob die Zahl deiner Glückszahl entspricht (denk dir hierfür einfach eine eigene Glückszahl aus und gib sie zu Beginn des Programms auf der Konsole aus)
- ob die Zahl zweistellig ist
Tipp: Für die ersten beiden Punkte wirst du die Modulo Funktion brauchen.
Aufgabe 2.2 Arbeits- oder Freizeit?
In der CODERS.BAY arbeiten wir von 8:30 bis 15:30 Uhr. Schreibe ein Programm, dass eine Zahl von der Konsole einliest und ausgibt ob die Stunde in der Arbeitszeit liegt oder nicht.
Bonus: von 12:00 bis 12:30 Uhr ist immer Mittagspause, gib also in der Zeit aus, dass Mittag ist.
Assignment and logical operators
Exercise 2.1 Characteristics of a number
Write a program that reads a number from the console and calculates and prints characteristics of it:
- is the number round
- is the number even
- does the number equal your lucky number (choose any lucky number for this and print it to the console at the start of the program)
- does it have two digits
Hint: You might find the modulo operation helpful for the first two exercises.
Exercise 2.2 free time or work time?
At CODERS.BAY we usually work from 8 to 16 o'clock. Write a program, that reads a number from the console and prints whether that hour is during our work time or not.
Bonus: We go for a lunch break between 12 and 13 o'clock, print that info in case the given number is between 12 and 13.
Bedingungen
Aufgabe 2.3: Noten übersetzen
Schreibe ein Programm, dass eine Schulnote in numerischer Form (1-5) in seine textuelle Form übersetzt:
- Bei einer 1 wird "Sehr gut" auf die Konsole geschrieben
- Bei einer 2 wird "Gut" auf die Konsole geschrieben
- Bei einer 3 wird "Befriedigend" auf die Konsole geschrieben
- Bei einer 4 wird "Genügend" auf die Konsole geschrieben
- Bei einer 5 wird "Nicht Gengügend" auf die Konsole geschrieben
Conditionals
Exercise: Translating grades
Write a program that translates grades from its numerical form to a word representation.
- Print "Very good" in case of a 1.
- Print "Good" in case of a 2.
- Print "Satisfactory" in case of a 3.
- Print "Sufficient" in case of a 4.
- Print "Not sufficient" in case of a 5.
Tag 3
Schleifen
Aufgabe: OachkatzlSchwoaf
OachkatzlSchwoaf ist ein Spiel um Kindern Division näher zu bringen. Die Regeln sind einfach - Reih um wird beginnend bei der Zahl 1 nach oben gezählt. Ist die Zahl durch drei teilbar, darf die Zahl allerdings nicht genannt werden - man muss Oachkatzl sagen, ist die Zahl durch fünf teilbar muss Schwoaf gesagt werden. Und - ist die Zahl durch drei und fünf teilbar, muss OachkatzlSchwoaf gesagt werden.
Als Beispiel: “Eins! Zwei! Oachkatzl(3)! Vier! Schwoaf(5)! Oachkatzl(6)! Sieben! Acht! Oachkatzl(9)! Schwoaf(10)! Elf! Oachkatzl(12)! Dreizehn! Vierzehn! OachkatzlSchwoaf(15)! Sechzehn!”
Schreibe ein Programm, dass die Zahlen von 1 - 100 nach diesem Schema ausgibt. Du musst die Zahlen nicht in Wortform ausgeben, numerisch reicht.
Aufgabe: Das kleine Einmal-Eins
Schreibe mit Hilfe von Schleifen das kleine 1 x 1 auf der Konsole aus. Deine Ausgabe sollte in etwa folgendermaßen aussehen:
1er Reihe: 1 * 1 = 1 2 * 1 = 2 ... 10 * 1 = 10 2er Reihe: 1 * 2 = 2 ... 9 * 10 = 90 10 * 10 = 100
Aufgabe: Caesar Chiffre
Wir wissen ja, dass jedes Zeichen in Java einen eindeutigen Code hat. Genauergesagt ist die numerische Repräsentation eines Characters/Zeichens der Unicode.
Die Caesar Chiffre ist ein simpler Verschlüsselungsalgorithmus bei dem alle Buchstaben um einen bestimmten offset X verschoben werden, erreichst du das Z solltest du wieder beim A starten, Sonderzeichen werden wir jetzt einmal auslassen.
Mit einer Caesar Chiffre von 6 würde aus dem Text:
Ein Charakter namens Caesar!
folgendes werden:
Kot Ingxgqzkx tgskty Igkygx!
wenn wir diesen Text nochmal um 6 verschlüsseln würde aus dem Text:
Quz Otmdmwfqd zmyqze Omqemd!
Schreibe ein Programm dass von der Konsole einen beliebiglangen Text einliest, danach zufällig einen Schlüssel zwischen 1 und 26 wählt und den verschlüsselten String ausgibt.
Arrays
Aufgabe: Berrechnung des Maximums
Schreibe ein kleines Programm, welches eine Liste von Zahlen über die Konsole zahlenweise einliest. Mit 'q' solltest du die Eingabe beenden können. Errechne dir danach aus der eben eingelesenen Liste das Maximum und gib es auf der Konsole aus.
Repetitions
Exercise: FizzBuzz
FizzBuzz is a game to explain divisions to children. The rules are simple - Starting with the number one players count up by one. Is the number dividable by three, you are not allowed to say the number but say "Fizz". Is it dividable by five "Buzz" needs to be said and if it's dividable by both three and five "FizzBuzz" needs to be said.
A round would start like this: “One! Two! Fizz(3)! Four! Buzz(5)! Fizz(6)! Seven! Eight! Fizz(9)! Buzz(10)!”
Write a program, that prints the numbers from 1 to 100 by those rules. You don't have to print the numbers as words, the numerical representation is sufficient.
Exercise: Multiplications
Use loops to print the 1 x 1 to the console. Your result should look something like this:
times 1: 1 * 1 = 1 2 * 1 = 2 ... 10 * 1 = 10 times 2: 1 * 2 = 2 ... 9 * 10 = 90 10 * 10 = 100
Exercise: Caesar Chiffre
We know that every letter in Java has a unique code. In detail the numerical representation of a character is the Unicode.
The caesar chiffre is a simple encryption algorithm, that rotates every letter with an offset X. When you reach the Z you should start again with the A for the purpose of this exercise. Moreover we will ignore all special characters for now.
With a Caesar Chiffre of 6 the following text
Ein Charakter namens Caesar!
would be encrypted to:
Kot Ingxgqzkx tgskty Igkygx!
when an encrypted again with a key of 6 we get:
Quz Otmdmwfqd zmyqze Omqemd!
Write a program that reads any text from the console, generates a key between 1 and 26 and prints the encrypted message.
Arrays
Exercise: Maxima calculation
Provide a program that reads numbers from the console until it reads the letter 'q'. Calculate the maximum of all values and print it to the console.
Tag 4
Kompetenzcheck
Aufgabe: Leetspeak
Schreibe ein kleines Programm, welches einen String über die Konsole einliest. Übersetzte den Text dann in Leetspeak - Du darfst dir hier eine beliebige Konfiguration verwenden, falls dir keine einfällt hier ein Vorschlag: Wenn du eine andere verwendest bitte in einer Markdown Datei deine Wahl angeben ;)
A => '@' B => '8' C => '(' D => 'D' E => '3' F => 'F' G => '6' H => '#' I => '!' J => 'J' K => 'K' L => '1' M => 'M' N => 'N' O => '0' P => 'P' Q => 'Q' R => 'R' S => '$' T => '7' U => 'U' V => 'V' W => 'W' X => 'X' Y => 'Y' Z => '2'
Exercise: Leetspeak
Provide a program that reads a String from the console. Translate it to Leetspeak and print the value to the console. You can choose any configuration you like, if you need inspiration, my example: If you choose a different one please provide a Markdown file with the mapping ;)
A => '@' B => '8' C => '(' D => 'D' E => '3' F => 'F' G => '6' H => '#' I => '!' J => 'J' K => 'K' L => '1' M => 'M' N => 'N' O => '0' P => 'P' Q => 'Q' R => 'R' S => '$' T => '7' U => 'U' V => 'V' W => 'W' X => 'X' Y => 'Y' Z => '2'