faecher:informatik:oberstufe:java:algorithmen:uebungen01:loesungsvorschlaege

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
faecher:informatik:oberstufe:java:algorithmen:uebungen01:loesungsvorschlaege [13.09.2021 12:58] – [A8] sbelfaecher:informatik:oberstufe:java:algorithmen:uebungen01:loesungsvorschlaege [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1
Zeile 1: Zeile 1:
-====== Lösungsvorschläge ====== 
- 
-===== A01 ===== 
- 
-++++ Lösungsvorschlag A01| 
-<code java> 
-public int 01MyModulo(int a, int b) 
-    { 
-        int remainder=0; 
-        // dein Code 
-        remainder = a - a/b*b; 
-        // Rückgabe 
-        return remainder; 
-    } 
-</code> 
- 
-oder  
- 
-<code java> 
-public int MyModulo(int a, int b) 
-    { 
-        return a - a/b*b; 
-    } 
-</code> 
-++++ 
- 
-===== A02 ===== 
- 
- 
-++++ Lösungsvorschlag A02| 
-<code java> 
-public void Switch(int a, int b)  
-    { 
-        System.out.println("Eingabe - a="+ a + " b="+b); 
- 
-        int c; 
-        c=a; 
-        a=b; 
-        b=c; 
-               
-        System.out.println("Ausgabe - a="+ a + " b="+b); 
-     } 
-</code> 
- 
-<code java> 
-public void Switch(int a, int b)  
-    { 
-        System.out.println("Eingabe - a="+ a + " b="+b); 
- 
-        b = a + b; 
-        a = b - a; 
-        b = b - a; 
-               
-        System.out.println("Ausgabe - a="+ a + " b="+b); 
-     } 
-</code> 
-++++ 
- 
-===== A03 ===== 
- 
- 
-++++ Lösungsvorschlag A03 | 
-<code> 
-public double a03Pyramide(double h, double a) { 
-        double v = 1.0/3.0*h*a*a; 
-        return v; 
-    } 
- 
-</code> 
-++++ 
- 
-===== A04 ===== 
- 
- 
-++++Lösungsvorschlag A04 | 
-<code java> 
-public void a04Alterstest(int alter) { 
-         
-        if ( alter < 7 ) { 
-            System.out.println("Nicht geschäftsfähig"); 
-        } else if ( alter < 18) { 
-            System.out.println("Eingeschränkt geschäftsfähig"); 
-         } else { 
-            System.out.println("Voll geschäftsfähig"); 
-         } 
-               
-    } 
-</code> 
-++++ 
- 
- 
- 
-===== A05 ===== 
-  
- 
-++++ Lösungsvorschlag A05 | 
-<code java> 
-public String a06gerade (int zahl) { 
-        int istungerade; 
-        istungerade = zahl % 2; 
-        if (istungerade == 0 ) {  
-             return "Zahl " zahl +" ist gerade";  
-        } else {  
-            return "Zahl "+ zahl +" ist ungerade";  
-        } 
-    } 
-</code> 
-++++ 
- 
- 
-===== A06 ===== 
- 
- 
-++++ Lösungsvorschlag A06 - 1 | 
-<code java> 
- public String a06schulnoten (double kommanote) { 
-        String textnote = ""; 
-         
-        kommanote = kommanote*100; 
-         
-        if (kommanote >= 550.0 ) { 
-            textnote = "Ungenügend"; 
-        } else if (kommanote >= 450.0 ) { 
-            textnote = "Mangelhaft"; 
-        } else if (kommanote >= 350.0 ) { 
-            textnote = "Ausreichend"; 
-        } else if (kommanote >= 250.0 ) { 
-            textnote = "Befriedigend"; 
-        } else if (kommanote >= 150.0 ) { 
-            textnote = "Gut"; 
-        } else { 
-            textnote = "Sehr gut"; 
-        } 
-         
-        return textnote;         
-         
-    } 
-</code> 
-++++ 
- 
-++++ Lösungsvorschlag A06 - 2 | 
-<code java> 
-public String a06schulnoten_2 (double kommanote) { 
-        String textnote = ""; 
-        int ganzenote; 
-         
-        // Was passiert hier? Erkläre!      
-        ganzenote = (int) (kommanote*100+50)/100; 
-         
-        switch(ganzenote){ 
-            case 1: 
-                textnote = "Sehr gut"; 
-                break; 
-            case 2: 
-                textnote = "Gut"; 
-                break; 
-            case 3: 
-                textnote = "Befriedigend"; 
-                break; 
-            case 4: 
-                textnote = "Ausreichend"; 
-                break; 
-            case 5: 
-                textnote = "Mangelhaft"; 
-                break; 
-            case 6: 
-                textnote = "Ungenügend"; 
-                break; 
-              
-        } 
-                 
-        return textnote;         
-         
-    } 
-</code> 
-++++ 
- 
- 
-===== A08 ===== 
- 
- 
-++++ Lösungsvorschlag A08 | 
-<code java> 
-public boolean a08schaltjahr(int jahr) 
-    { 
-         
-        if ( (jahr % 4 == 0 && jahr % 100 != 0 && jahr % 400 != 0) || (jahr % 400 == 0) ) { 
-            return true; 
-        } 
-         
-        return false; 
-    } 
-</code> 
-++++ 
- 
-===== A09 ===== 
- 
- 
-++++ Lösungsvorschlag A09 | 
-<code java> 
-public int a09stellenzaehler(int zahl) 
-    { 
-        int stellen=0; 
-         
-        while (zahl > 0) { 
-            zahl = zahl / 10; 
-            stellen++; 
-        } 
-         
-        return stellen; 
-    } 
-</code> 
-++++ 
- 
-===== A0 ===== 
- 
- 
-++++ Lösungsvorschlag A0 | 
-<code java> 
- 
-</code> 
-++++ 
- 
-===== Lotto ===== 
- 
- 
-++++ Lösungsvorschlag Lotto | 
-<code java> 
-public void a05lottozahlen () { 
-         
-        int anzahl = 9; 
-        int[] lzahlen = new int[anzahl]; 
-         
-        for (int i = 0; i<anzahl; i++) { 
-                lzahlen[i]=i+1; 
-        } 
- 
-        int num_gezogen = 0; 
-        while (num_gezogen < 6) { 
-            int posgezogen = (int) (Math.random() * anzahl ); 
-            if (lzahlen[posgezogen] != 0 ) { 
-                System.out.println(lzahlen[posgezogen]); 
-                lzahlen[posgezogen] = 0; 
-                num_gezogen++; 
-            } else { 
-                int schongezogen = posgezogen + 1; 
-                System.out.println("Nochmal... (" + schongezogen +")" ); 
-            } 
-        } 
-    } 
-</code> 
-++++ 
- 
  
  • faecher/informatik/oberstufe/java/algorithmen/uebungen01/loesungsvorschlaege.1631530733.txt.gz
  • Zuletzt geändert: 13.09.2021 12:58
  • von sbel