Java:
import java.util.ArrayList;
import org.riediger.jconsole.JConsole;
public class Ships {
private String name;
private int[] location;
public void setLocation(int[] array) {
location = array;
}
public String[] createShip() {
ArrayList<String> vertical = new ArrayList<String>();
String[] array = { "A", "B", "C", "D", "E", "F" };
for (String count : array) {
vertical.add(count);
}
String[] cords = new String[2];
cords[0] = vertical.get((int) Math.random() * vertical.size());
cords[1] = "" + ((int) Math.random() * 6);
return cords;
}
public static void main(String[] args) {
JConsole.start();
Ships one = new Ships();
String[] array = new String[2];
array = one.createShip();
System.out.println(array[0]);
System.out.println(array[1]);
}
}
Hallo,
Java:
String[] cords = new String[2];
cords[0] = vertical.get((int) Math.random() * vertical.size());
cords[1] = "" + ((int) Math.random() * 6);
gibt mir jedes mal den output "A0". eigentlich sollte es zufällig eine koordiante generieren zB B3 A6 F2 etc. Was habe ich falsch gemacht ?
danke