/Users/teofilomatos/Documents/isep/APROG_2010_2011/projectos/PL7_EX_DEM2/src/pl7_ex_dem2/Main.java |
1 package pl7_ex_dem2;
2
3 import java.util.Formatter;
4 import java.util.Scanner;
5
6
7 @author
8
9 public class Main {
10
11 private static Scanner ler = new Scanner(System.in);
12 private static Formatter esc = new Formatter(System.out);
13
14
15 private static int lerNumeroEquipas() {
16 int numEquipas;
17
18 do {
19 esc.format("Número de Equipas:");
20 numEquipas = ler.nextInt();
21 } while (numEquipas < 1);
22
23 return numEquipas;
24 }
25
26
27 private static void lerEquipas(String[][] mat) {
28 esc.format("Leitura das Equipas%n");
29
30 for (int col = 0; col < mat[0].length; col++) {
31 esc.format("Equipa %d%n", col + 1);
32 for (int lin = 0; lin < mat.length; lin++) {
33 esc.format("Jogador %d:", lin + 1);
34 mat[lin][col] = ler.next();
35 }
36 }
37 }
38
39
40
41
42
43
44
45
46
47
48 private static int numeroColunasOrdenadas(String[][] mat) {
49 int c = 0, lin;
50
51 for (int col = 0; col < mat[0].length; col++) {
52 lin = 0;
53
54 while (lin < mat.length - 1 && mat[lin][col].compareToIgnoreCase(mat[lin + 1][col]) < 0) {
55 lin++;
56 }
57
58
59 if (lin == mat.length - 1) {
60 c++;
61 }
62 }
63 return c;
64 }
65
66
67
68
69
70
71
72
73
74
75
76
77
78 public static void main(String[] args) {
79 int n = lerNumeroEquipas();
80
81 String equipas[][] = new String[5][n];
82
83 lerEquipas(equipas);
84
85 esc.format("%nNúmero de Equipas Ordenadas: %d%n", numeroColunasOrdenadas(equipas));
86 }
87 }
88
89