Java – die besten Beiträge

Java Chess programmieren?

Hallo,

ich soll ein Chess Programm schreiben, welches eine positive, ganze Zahl n als Argument von der Konsole übergeben bekommt und ein Schachbrett der Größe n × n auf der Standardausgabe ausgibt. Das Brett beginnt oben links mit einem schwarzen Feld. Wenn kein Argument angegeben wird oder die eingegebene Zahl negativ ist, soll das Programm eine Fehlermeldung ausgeben, welche mit ERROR beginnt. Ich schreibe das Programm mit Eclipse

Das hab ich bis jetzt:

  public static void main(String args[]) {

  

   int breite = 5;

  

  

   System.out.println("* * *");

   System.out.println(" * * ");

   System.out.println("* * *");

   System.out.println(" * * ");

   System.out.println("* * *");

  

   for(int anzahlSterne = 1; anzahlSterne <= breite; anzahlSterne++) {

   System.out.println(anzahlSterne);

   for(int sternnummer = 1; sternnummer <= anzahlSterne; sternnummer++) {

   System.out.print("* ");

   }

   System.out.println();

  

   {

  

   }

  

   }

   for(int anzahlSterne = breite -1; anzahlSterne <= 1; anzahlSterne++) {

   System.out.println(anzahlSterne);   

   for(int sternnummer = 1; sternnummer <= anzahlSterne; sternnummer++) {

   System.out.print("* ");

   }

   System.out.println();

   }

  }

   

}

Ich komme halt echt nicht weiter und ich sitze seit zwei Tagen an den Aufgaben. Kann mir vielleicht jemand helfen?

Mit freundlichen Grüßen

Computer, Studium, Schule, programmieren, Java, Informatik, Universität, Schachbrett, eclipse java

Java array rückwärts?

package uebung1;
import java.util.Random;
public class Felder {
public int[] fuellen(int o, int l) {
int zahlen[] = new int[l];
Random rnd = new Random();
for (int x = 0; x < zahlen.length; x++) {
zahlen[x] = rnd.nextInt(o + 1);
}
return zahlen;
}
public int[] fuellen(int u, int o, int l) {
int zahlen[] = new int[l];
Random rnd = new Random();
for (int x = 0; x < zahlen.length; x++) {
zahlen[x] = rnd.nextInt(o - u) + u;
}
return zahlen;
}
public void ausgeben(int zahlen[]) {
for (int x = 0; x < zahlen.length; x++) {
if (x == 0) {
System.out.print("[");
}
System.out.print(zahlen[x]);
if (x != zahlen.length - 1) {
System.out.print(", ");
}
if (x == zahlen.length - 1) {
System.out.println("]");
}
}
}
public void ausgebenrueckwaerts(int zahlen[]) {
for (int x = zahlen.length-1; x >= 0; x--) {
if (x == zahlen.length-1) {
System.out.print("[");
}
System.out.print(zahlen[x]);
if (x != 0) {
System.out.print(", ");
}
if (x == 0) {
System.out.println("]");
}
}
}
public void drei_fuenf(int zahlen[]) {
for (int x = 0; x < zahlen.length; x++) {
if (zahlen[x] % 3 == 0 && zahlen[x] % 5 == 0) {
System.out.println("Hello Zahl: " + zahlen[x]);
} else if (zahlen[x] % 3 == 0) {
System.out.println("Fizz Zahl: " + zahlen[x]);
} else if (zahlen[x] % 5 == 0) {
System.out.println("Buzz Zahl: " + zahlen[x]);
}
}
}
public boolean finde(int z, int zahlen[]) {
boolean found = false;
for (int x = 0; x < zahlen.length; x++) {
if (zahlen[x] == z) {
found = true;
break;
}
}
return found;
}
public int finde_pos(int z, int zahlen[]) {
int pos = -1;
for (int i = 0; z != zahlen[i]; i++) {
pos++;
}
pos++;
return pos;
}
public int finde_anz(int z, int zahlen[]) {
int anz = 0;
for (int i = 0; i < zahlen.length; i++) {
if (zahlen[i] == z) {
anz++;
}
}
return anz;
}
}
programmieren, Java

Meistgelesene Beiträge zum Thema Java