Commit 71446997 authored by Dominikus Herzberg's avatar Dominikus Herzberg

Einfaches printf geändert zu System.out.printf

parent d3a34cd1
......@@ -2,8 +2,8 @@
void printP(int[][] triangle){
for(int n = 0; n < triangle.length; n++){
for(int k = 0; k < triangle[n].length; k++){
printf("%d ", triangle[n][k]);
System.out.printf("%d ", triangle[n][k]);
}
printf("\n");
System.out.printf("\n");
}
}
void printArray2D(int[][] a) {
for(int i = 0; i < a.length; i++) {
for(int j = 0; j < a[i].length; j++) {
printf("%2d ", a[i][j]);
System.out.printf("%2d ", a[i][j]);
}
printf("\n");
System.out.printf("\n");
}
}
......
void printArray2D(int[] a, int w) {
for(int i = 0; i < a.length; i++) {
if(i > 0 && i % w == 0) printf("\n");
printf("%2d ", a[i]);
if(i > 0 && i % w == 0) System.out.printf("\n");
System.out.printf("%2d ", a[i]);
}
printf("\n");
System.out.printf("\n");
}
int[] test = {
......
......@@ -15,4 +15,4 @@ int n = 1000;
for(int i = 0; i < n; i++) {
x += rollDoubles();
}
printf("Durchschnittliche Würfe bis zum Pasch: %.3f", 1.0 * x / n); // <1>
\ No newline at end of file
System.out.printf("Durchschnittliche Würfe bis zum Pasch: %.3f", 1.0 * x / n); // <1>
\ No newline at end of file
......@@ -19,9 +19,9 @@ class Airplane{
public void fly(int speed){
if(this.maxSpeed >= speed){
printf("Flugzeug %s fliegt %d mph.", this.name, speed);
System.out.printf("Flugzeug %s fliegt %d mph.", this.name, speed);
} else{
printf("Zu schnell! Flugzeug %s darf nur maximal %d mph fliegen.", this.name, this.maxSpeed);
System.out.printf("Zu schnell! Flugzeug %s darf nur maximal %d mph fliegen.", this.name, this.maxSpeed);
}
}
......@@ -29,7 +29,7 @@ class Airplane{
for (int i = 0; i < planes.length; i++){
if(planes[i] != null){
planes[i].fly(1000);
printf("\n");
System.out.printf("\n");
}
}
}
......
......@@ -33,27 +33,27 @@ Player opponent = new Player();
while(player.canPlay() || opponent.canPlay()) {
if(player.canPlay()) {
player.play(deck);
printf("Eigene Summe: %d\n", player.sum);
System.out.printf("Eigene Summe: %d\n", player.sum);
int choice = JOptionPane.showConfirmDialog(null, "Nächste Karte?");
player.playing = choice == JOptionPane.YES_OPTION;
}
if (opponent.canPlay()) {
printf("Der Gegner nimmt noch eine Karte.\n");
System.out.printf("Der Gegner nimmt noch eine Karte.\n");
opponent.play(deck);
opponent.playing = Math.random() > opponent.sum / 21.0;
if (!opponent.playing) {
printf("Der Gegner steigt aus.\n");
System.out.printf("Der Gegner steigt aus.\n");
}
}
}
printf("Gegnerische Summe: %d\n", opponent.sum);
System.out.printf("Gegnerische Summe: %d\n", opponent.sum);
if (player.sum > 21) {
printf("Leider verloren!\n");
System.out.printf("Leider verloren!\n");
} else if (player.sum == 21) {
printf("Genau 21, super!\n");
System.out.printf("Genau 21, super!\n");
} else if (player.sum > opponent.sum || opponent.sum > 21) {
printf("Gewonnen!\n");
System.out.printf("Gewonnen!\n");
} else {
printf("Leider verloren!\n");
System.out.printf("Leider verloren!\n");
}
\ No newline at end of file
......@@ -3,9 +3,9 @@ char[][] image = new char[10][20];
void printImage(char[][] image) {
for(int y = 0; y < image.length; y++) {
for(int x = 0; x < image[y].length; x++) {
printf(String.valueOf(image[y][x]));
System.out.printf(String.valueOf(image[y][x]));
}
printf("\n");
System.out.printf("\n");
}
}
......
......@@ -33,6 +33,6 @@ Boolean[] test = {
new Fraction(3,4).div(new Fraction(5,4)).toString().equals("3/5"),
}
printf("%d tests: discovered %d error(s)!\n",
System.out.printf("%d tests: discovered %d error(s)!\n",
test.length,
Arrays.stream(test).filter(n -> n == false).count());
......@@ -39,6 +39,6 @@ Boolean[] test = {
test1(), test2(), test3(), test4(), test5()
}
printf("%d tests: discovered %d error(s)!\n",
System.out.printf("%d tests: discovered %d error(s)!\n",
test.length,
Arrays.stream(test).filter(n -> n == false).count());
\ No newline at end of file
......@@ -44,34 +44,34 @@ Unit randomUnitAlive(Unit[] army) {
void printArmy(Unit[] army) {
for(Unit u : army) {
if(u.number > 0) {
printf(" %3d %10s\n", u.number, u.type);
System.out.printf(" %3d %10s\n", u.number, u.type);
}
}
}
void simulateBattle(Unit[] blue, Unit[] red) {
printf("Blau:\n");
System.out.printf("Blau:\n");
printArmy(blue);
printf("Rot:\n");
System.out.printf("Rot:\n");
printArmy(red);
while(fighterSum(blue) != 0 && fighterSum(red) != 0) {
Unit blueUnit = randomUnitAlive(blue);
Unit redUnit = randomUnitAlive(red);
printf("%s gegen %s:\n", blueUnit.toString("blaue"), redUnit.toString("rote"));
System.out.printf("%s gegen %s:\n", blueUnit.toString("blaue"), redUnit.toString("rote"));
int kcBlue = blueUnit.killCount(redUnit);
int kcRed = redUnit.killCount(blueUnit);
printf(" %3d %5s %10s sterben\n", kcBlue, "rote", redUnit.type);
printf(" %3d %5s %10s sterben\n", kcRed, "blaue" , blueUnit.type);
System.out.printf(" %3d %5s %10s sterben\n", kcBlue, "rote", redUnit.type);
System.out.printf(" %3d %5s %10s sterben\n", kcRed, "blaue" , blueUnit.type);
blueUnit.number -= kcRed;
redUnit.number -= kcBlue;
}
if (fighterSum(blue) > 0) {
printf("Blau gewinnt und behält:\n");
System.out.printf("Blau gewinnt und behält:\n");
printArmy(blue);
} else if (fighterSum(red) > 0) {
printf("Rot gewinnt und behält:\n");
System.out.printf("Rot gewinnt und behält:\n");
printArmy(red);
} else {
printf("Alle Einheiten wurden getötet. Es gibt keinen Gewinner.\n");
System.out.printf("Alle Einheiten wurden getötet. Es gibt keinen Gewinner.\n");
}
}
......
......@@ -9,15 +9,15 @@ Animal[] a = {a0, a1, a2, a3};
for (int i = 0; i < a.length; i++){
if(a[i] != null){
printf ("%s \n", a[i].getIdentity());
System.out.printf ("%s \n", a[i].getIdentity());
}
}
for (int i = 0; i < a.length; i++){
if(a[i] != null){
printf ("%s \n", a[i].makeSound(i+1));
System.out.printf ("%s \n", a[i].makeSound(i+1));
}
}
printf ("Zusammen sind wir %d Jahre alt.", Animal.countAllAges(a));
System.out.printf ("Zusammen sind wir %d Jahre alt.", Animal.countAllAges(a));
......@@ -6,7 +6,7 @@ class Medium {
this.dur = dur;
}
void play() {
printf("Playing %s\n", title);
System.out.printf("Playing %s\n", title);
}
int getDurationSeconds() {
return dur;
......@@ -34,7 +34,7 @@ class Album extends Medium {
}
void play() {
super.play();
printf("Current track: %s\n", tracks[currentTrack]);
System.out.printf("Current track: %s\n", tracks[currentTrack]);
}
void nextTrack() {
currentTrack = (currentTrack + 1) % tracks.length;
......
......@@ -7,7 +7,7 @@ class Video {
this.dur = dur;
}
void play() {
printf("Playing %s\n", title);
System.out.printf("Playing %s\n", title);
}
void setSubtitles(boolean on) {
subtitles = on;
......@@ -28,8 +28,8 @@ class Album {
this.trackDurations = trackDurations;
}
void play() {
printf("Playing %s\n", title);
printf("Current track: %s\n", tracks[currentTrack]);
System.out.printf("Playing %s\n", title);
System.out.printf("Current track: %s\n", tracks[currentTrack]);
}
void nextTrack() {
currentTrack = (currentTrack + 1) % tracks.length;
......
......@@ -20,4 +20,4 @@ Point[] points = {
new Point(3,3)
};
Arrays.sort(points);
printf(Arrays.toString(points));
\ No newline at end of file
Syste.out.printf(Arrays.toString(points));
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment