Difference between revisions of "Java - Einführung"

From Coders.Bay Wiki
Jump to navigation Jump to search
Line 21: Line 21:
138 + 235 = 373
138 + 235 = 373
138 - 235 = -97
138 - 235 = -97
==== Aufgabe 1.3 - Arbeiten mit Strings [🤓 Advanced] ====
Lege einen String mit dem Inhalt “ Hello World! ” an (enthält vorne und hinten Leerzeichen).
    *Gib den String und seine Länge auf der Konsole aus.
    *Gib den String in einigen Abwandlungen auf der Konsole aus:
        **alle Buchstaben in Großbuchstaben
        **alle Buchstaben in Kleinbuchstaben
        **ersetze “World” mit “Codersbay”
        **ohne Leerzeichen zu Beginn des Texts
    *Gib den String 15 mal wiederholt mit einem Zeilenumbruch zum Trennen aus (ohne die Codezeile 15 mal zu kopieren 😉)
Suche auf der offiziellen Dokumentations-Seite von Strings nach nützlichen Methoden.


===Variables and Datatypes===
===Variables and Datatypes===
Line 40: Line 54:
138 + 235 = 373
138 + 235 = 373
138 - 235 = -97
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.

Revision as of 15:33, 19 December 2021

Woche 1

Variablen und Datentpyen

Aufgabe 1.1 - Erzähl mir etwas über dich

Deklariere Variablen für dein Alter, deinen Vornamen, dein Geschlecht, deinen Nachnamen, dein Geburtsdatum, deinen Notendurchschnitt und dafür ob du verheiratet bist oder nicht. Überleg dir gut welchen Datentyp du für welche Variablen am besten verwenden solltest.

Gib alle Variablen mit System.out.println auf der Konsole aus.

Aufgabe 1.2 - Einfache Rechenaufgaben

Deklariere zwei numerische Variablen mit beliebigen Werten. Errechne deren Summe, Differenz, Produkt und Quotient und gib die Rechnung mit dem Ergebnis mit System.out.println/System.out.printf auf der Konsole aus. Rechne einmal mit ganzzahligen und einmal mit gebrochenen Zahlen!

Bonus: Gib die Kommazahlen schön formatiert auf der Konsole aus.

Eine Ausgabe sollte folgendermaßen aussehen:

Beispiel Ausgabe

138 + 235 = 373 138 - 235 = -97

Aufgabe 1.3 - Arbeiten mit Strings [🤓 Advanced]

Lege einen String mit dem Inhalt “ Hello World! ” an (enthält vorne und hinten Leerzeichen).

   *Gib den String und seine Länge auf der Konsole aus.
   *Gib den String in einigen Abwandlungen auf der Konsole aus:
       **alle Buchstaben in Großbuchstaben
       **alle Buchstaben in Kleinbuchstaben
       **ersetze “World” mit “Codersbay”
       **ohne Leerzeichen zu Beginn des Texts
   *Gib den String 15 mal wiederholt mit einem Zeilenumbruch zum Trennen aus (ohne die Codezeile 15 mal zu kopieren 😉)

Suche auf der offiziellen Dokumentations-Seite von Strings nach nützlichen Methoden.

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.