1.- The following countries participate in a championship: "Spain", "France", "United Kingdom", "Italy", "Germany" and "Denmark". Each country gets a score (between 1 and 10 that is generated randomly). It is requested to calculate the countries that have obtained the first and second prize. (There may be several countries with the same score). It is asked to solve the problem using arrays.
Example: assuming that the order of the countries is the previous one and that the scores are respectively 8, 9, 5, 6, 7, 3 the output would be: Winner of the first prize: France Second prize: Spain
package arrays;
public class Paises {
public static void main(String[] args) {
String[] listaPaises= {"España", "Francia", "Reino Unido", "Italia", "Alemania","Dinamarca"};
int max =Integer.MIN_VALUE,posPai = -1;
for (int i = 0; i < listaPaises.length; i++) {
int puntuaciones = (int)(Math.random()*9+1);
System.out.print(puntuaciones+" ");
if (puntuaciones>max) {
max=puntuaciones;
posPai = i;
listaPaises[posPai]+=" "+listaPaises[i];
}
//listaPaises[i]
}
System.out.println(" "+max);
System.out.println("El ganador es "+listaPaises[posPai]);
}
}
I've tried it in several ways but I do not give it with the key.