Dies ist eine alte Version des Dokuments!
Die Lösungsvorschläge sind absichtlich unkommentiert. Du solltest sie verstehen und deinem Banknachbarn erklären können, damit sie einen Nutzen haben1). Idealerweise fügst du nach der Besprechung entsprechende Kommentare in den Code ein.
Lösungsvorschlag A01
public int 01MyModulo(int a, int b)
{
int remainder=0;
// dein Code
remainder = a - a/b*b;
// Rückgabe
return remainder;
}
oder
public int MyModulo(int a, int b)
{
return a - a/b*b;
}
Lösungsvorschlag A02
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);
}
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);
}
Lösungsvorschlag A03
public double a03Pyramide(double h, double a) {
double v = 1.0/3.0*h*a*a;
return v;
}
Lösungsvorschlag A04
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");
}
}
Lösungsvorschlag A05
public String a06gerade (int zahl) {
int istungerade;
istungerade = zahl % 2;
if (istungerade == 0 ) {
return "Zahl "+ zahl +" ist gerade";
} else {
return "Zahl "+ zahl +" ist ungerade";
}
}
Lösungsvorschlag A06 - 1
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;
}
Lösungsvorschlag A06 - 2
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;
}
Lösungsvorschlag A08
public boolean a08schaltjahr(int jahr)
{
if ( (jahr % 4 == 0 && jahr % 100 != 0 && jahr % 400 != 0) || (jahr % 400 == 0) ) {
return true;
}
return false;
}
Lösungsvorschlag A09
public int a09stellenzaehler(int zahl)
{
int stellen=0;
while (zahl > 0) {
zahl = zahl / 10;
stellen++;
}
return stellen;
}
Lösungsvorschlag A11
public int a11dual2dec(int dual)
{
int stellenziffer=0;
int stellenwert=1;
int dezimalwert=0;
while (dual > 0) {
stellenziffer = dual % 10;
dezimalwert = dezimalwert + stellenziffer * stellenwert;
stellenwert = stellenwert * 2;
dual = dual / 10;
}
return dezimalwert;
}
Lösungsvorschlag Lotto
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 +")" );
}
}
}