Merge pull request 'update printf/suche/rechner' (#6) from großerPC into master

Reviewed-on: #6
pull/10/head
Kai Sellmann 2023-04-27 10:47:00 +02:00
commit c61ece3b2b
3 changed files with 69 additions and 13 deletions

View File

@ -1,18 +1,47 @@
package pr2.auffrischung.printf;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class DoubleFormatter {
public static void printDouble(double d) {
// TODO: Wert ausgeben
String format = "0.000";
NumberFormat formatter = new DecimalFormat(format);
String newD = formatter.format(d);
System.out.print("Mit Formatting: " + newD);
System.out.println();
}
public static void main(String[] args) {
printDouble(1.0);
printDouble(10.1);
printDouble(2.01);
printDouble(2.001);
printDouble(2.0001);
printDouble(2.0004);
printDouble(2.0005);
double dVal1 = 1.0;
printDouble(dVal1);
System.out.printf("Mit printf: %.3f", dVal1);
System.out.println();
double dVal2 = 10.1;
printDouble(dVal2);
System.out.printf("Mit printf: %.3f", dVal2);
System.out.println();
double dVal3 = 2.01;
printDouble(dVal3);
System.out.printf("Mit printf: %.3f", dVal3);
System.out.println();
double dVal4 = 2.001;
printDouble(dVal4);
System.out.printf("Mit printf: %.3f", dVal4);
System.out.println();
double dVal5 = 2.0001;
printDouble(dVal5);
System.out.printf("Mit printf: %.3f", dVal5);
System.out.println();
double dVal6 = 2.0004;
printDouble(dVal6);
System.out.printf("Mit printf: %.3f", dVal6);
System.out.println();
double dVal7 = 2.0005;
printDouble(dVal7);
System.out.printf("Mit printf: %.3f", dVal7);
System.out.println();
}
}

View File

@ -5,8 +5,17 @@ public class GroessteZahl {
public int sucheMax(int[] zahlen) {
int max = 0;
// TODO: Methode implementieren
for (int i = 0; i < zahlen.length; i++) {
if (max > zahlen[i]) {
max = zahlen[i];
}
}
for (int i = 0; i < zahlen.length; i++) {
if (max < zahlen[i]) {
max = zahlen[i];
}
}
return max;
}

View File

@ -3,8 +3,26 @@ package pr2.auffrischung.taschenrechner;
public class Taschenrechner {
public double rechne(double o1, char op, double o2) {
// TODO: Implementieren
return 0.0;
switch (op) {
case '+':
return o1 + o2;
case '-':
return o1 - o2;
case '*':
return o1 * o2;
case '/':
if (o2 == 0) {
return o2;
} else {
return o1 / 02;
}
case '^':
return Math.pow(o1, o2);
default:
return 0.0;
}
}
public static void main(String[] args) {
@ -13,6 +31,6 @@ public class Taschenrechner {
System.out.println(t.rechne(1, '-', 2));
System.out.println(t.rechne(2, '*', 2));
System.out.println(t.rechne(4, '/', 2));
System.out.println(t.rechne(2, '^', 32));
System.out.println(t.rechne(2, '^', 3));
}
}