1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| import java.util.Arrays;
import java.util.Scanner;
public class Ville
{
Scanner sc = new Scanner(System.in);
String nomVille;
String nomPays;
int nbreHabitants;
int h1, h2, h3, h4;
String v1, v2, v3, v4;
public Ville()
{
nomVille = "Inconnu";
nomPays = "Inconnu";
nbreHabitants = 0;
}
public Ville(String pNom, int pNbre, String pPays)
{
nomVille = pNom;
nomPays = pPays;
nbreHabitants = pNbre;
}
public void VillePrint()
{
System.out.println(nomVille + ", " + nomPays + ", " + nbreHabitants + " habitants ");
}
public void VilleCreation()
{
System.out.print("nom : ");
nomVille = sc.nextLine();
System.out.print("pays : ");
nomPays = sc.nextLine();
System.out.print("nombre d'habitants : ");
nbreHabitants = sc.nextInt();
}
public void Ville1Hab()
{h1 = nbreHabitants; v1 = nomVille; System.out.print(h1);}
public void Ville2Hab()
{h2 = nbreHabitants; v2 = nomVille;}
public void Ville3Hab()
{h3 = nbreHabitants; v3 = nomVille;}
public void Ville4Hab()
{h4 = nbreHabitants; v4 = nomVille;}
public void VilleTop()
{
int t1, t2, t3, t4;
String tt1, tt2, tt3, tt4;
System.out.println("Classement de la population des quatres villes :");
System.out.print(h1);
int t[] = {h1, h2, h3, h4};
System.out.print(h1);
System.out.print(" y " + h1 + h2 + h3 + h4);
Arrays.sort(t);
t4 = t[0];
t3 = t[1];
t2 = t[2];
t1 = t[3] ;
System.out.println(t1);
System.out.println(t4);
}
} |
Partager