When I enter the amount of albums sold by different artists, how can I detect the person who sold the most?

1
package cantanteFamoso;

import java.util.ArrayList;
import java.util.Scanner;

public class ListaCantantesFamosos extends cantanteFamoso   {


    public ListaCantantesFamosos(String nombre, String pais) {
        super(nombre, pais, discosVendidos);
        ArrayList<String> listaCantantesFamosos = new ArrayList<String>();

        listaCantantesFamosos.add(pais);
        listaCantantesFamosos.add(nombre);


    }
    public void lista(int n){
        Scanner teclado = new Scanner(System.in);
        for (int i = 0; i < n ; i++) {
            System.out.println("ingrese nombre");
            String nombre=(String) teclado.nextLine();
            System.out.println("#"+i+" su nombre es "+nombre);
            System.out.println("ingrese pais");
            String pais=(String) teclado.nextLine();

            Discos listaCantantesFamosos=new Discos(generoMusica, nombreDisco, 0);
            System.out.println("genero musical");
            String generoMusical=(String) teclado.nextLine();
            System.out.println("nombre disco");
            String nombreDisco=(String) teclado.nextLine();
            System.out.println("numero discos vendidos");
            int discosVendidos=(int) teclado.nextInt();
            System.out.println("el pais de "+nombre+" es "+ pais+", que vendio "+ discosVendidos+"discos de nombre"+ nombreDisco);


        }
        for (int i = 0; i < n; i++) {

        }
    }
}
    
asked by santiago londoño velez 30.04.2018 в 17:17
source

1 answer

1

Suppose I have the following list:

int[] listaDiscos = {10,40,70,80,90,20,70,150,400,600,900,800};

To begin with, we will assume that the largest is the first and that consequently its position is zero.

int mayor
mayor = listaDiscos[0];

We will go through the entire array, for each element of the array that we go through we will have to ask if this element is greater than the one we have stored.

    for (int x=1;x<listaDiscos.length;x++){
     if (listaDiscos[x]>mayor){
       mayor = listaDiscos[x];
     } 
    }

now you will only have to show the largest number ( major ) !!

    
answered by 30.04.2018 в 17:29