Hilfe bitte. Ich versuche, ein Programm zu schreiben, um Entfernungen zwischen Stationen zu berechnen. Ich möchte eine Eingabe von Benutzern erhalten, wo sie sind und wohin sie gehen möchten. das ist was ich bisher habe. ich stecke fest. was tue ich als nächstes?shortpath. Entfernungsberechnung Java.
import java.util.Arrays;
public class StationDist {
public static void main(String[] args) {
double[] stations = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
//Set up the stations array of doubles here
double[][] distances = new double[stations.length][];
for(int i=0; i < stations.length; i++) {
distances[i] = new double[i+1];
for(int j=0; j<distances[i].length; j++) {
distances[i][j] = Math.abs(stations[i] - stations[j]);
}
//System.out.println(Arrays.toString(distances[i]));
}
System.out.println("Enter the destnation: ");
System.out.println("1 for london.");
System.out.println("2 for bristol");
System.out.println("3 for oxford");
System.out.println("4 for warwick");
KeyboardInput in = new KeyboardInput();
int val = in.readInteger();
System.out.println(Arrays.toString(distances[val]));
}
}
Also sind die Abstände gerade Linien? Ich bin ein wenig verwirrt, da ich denken würde, dass Sie eine Graphenstruktur wollen, um zum Beispiel Dijkstras Algorithmus zu verwenden, aber ich bin mir nicht sicher, was der Kontext Ihrer Hausaufgabe ist. –