Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ejerciciosArraysTema4;
- import java.util.Scanner;
- public class Ejercicio5 {
- public static void main(String[] args) {
- String[] vector = {"Madrid", "Barcelona", "Valencia", "Zaragoza"};
- String ciudadInicio, ciudadFin;
- int x = 0;
- int y = 0;
- String[][] distancias =
- {{"0", "600", "300", "400"},
- {"600", "0", "200", "300"},
- {"300", "200", "0", "300"},
- {"400", "300", "300", "0"}};
- Scanner lector = new Scanner(System.in);
- System.out.println("Introduce el nombre de la ciudad de inicio: ");
- ciudadInicio = lector.next();
- System.out.println("Introduce el nombre de la ciudad de fin: ");
- ciudadFin=lector.next();
- for ( int i = 0 ; i < vector.length ; i++ ) {
- if ( vector[i].equalsIgnoreCase(ciudadInicio) ) {
- x=i;
- }
- }
- for ( int j = 0 ; j < vector.length ; j++ ) {
- if ( vector[j].equalsIgnoreCase(ciudadFin) ) {
- y=j;
- }
- }
- System.out.println("La distancia entre " + ciudadInicio + " y " + ciudadFin + " son " + distancias[x][y] + " kilometros");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement