Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. public class AulaVetores {
  2. public static void main(String[] args) {
  3. double notas[] = {8.0, 7.5, 8.5, 6.5, 5.1, 10.0, 6.5, 4.4, 5.9, 6.0};
  4. //Atividades
  5. //q1
  6. System.out.println("Média = "+calculaMedia(notas));
  7. System.out.println("Quantidade de notas abaixo de 6.0: "+quantidadeAbaixo6(notas));
  8. System.out.println("Quantidade de notas acima/igual de 6.0: "+quantidadeAcimaIgual6(notas));
  9. System.out.println("Quantidade acima/igual média: "+quantidadeAcimaIgualMedia(notas));
  10. System.out.println("Maior nota do vetor: "+maiorNota(notas));
  11. System.out.println("Menor nota do vetor: "+menorNota(notas));
  12. System.out.println("Existem notas repetidas? "+existemRepetidas(notas));
  13. }
  14. public static double calculaMedia(double notas[]) {
  15. double soma = 0;
  16. for (int i = 0; i < notas.length; i++) {
  17. soma = soma + notas[i];
  18. }
  19. double media = (double)soma/notas.length;
  20. return media;
  21. }
  22. public static int quantidadeAbaixo6(double[] notas) {
  23. int contador = 0;
  24. for (int i = 0; i < notas.length; i++) {
  25. if (notas[i] < 6.0) contador++;
  26. }
  27. return contador;
  28. }
  29. public static int quantidadeAcimaIgual6(double[] notas) {
  30. int contador = 0;
  31. for (int i = 0; i < notas.length; i++) {
  32. if (notas[i] >= 6.0) contador++;
  33. }
  34. return contador;
  35. }
  36. public static int quantidadeAcimaIgualMedia(double[] notas) {
  37. int contador = 0;
  38. double media = calculaMedia(notas);
  39. for (int i = 0; i < notas.length; i++) {
  40. if (notas[i] >= media) contador++;
  41. }
  42. return contador;
  43. }
  44. public static double maiorNota(double[] notas) {
  45. double maior = notas[0];
  46. for (int i = 0; i < notas.length; i++) {
  47. if (notas[i]>maior) maior = notas[i];
  48. }
  49. return maior;
  50. }
  51. public static double menorNota(double[] notas) {
  52. double menor = notas[0];
  53. for (int i = 0; i < notas.length; i++) {
  54. if (notas[i]<menor) menor = notas[i];
  55. }
  56. return menor;
  57. }
  58. public static boolean existemRepetidas(double[] notas) {
  59. boolean existe = false;
  60.  
  61. for (int i = 0; i < notas.length; i++) {
  62. for (int j = 0; j < notas.length; j++) {
  63. if (j != i)
  64. if (notas[i] == notas[j])
  65. existe = true;
  66. if (existe) break;
  67. }
  68. if (existe) break;
  69. }
  70.  
  71. return existe;
  72. }
  73. public static double[] notaMaisRepetida(double[] notas) {
  74. double maisRepetida = notas[0];
  75. double numeroRepeticoes[] = new double[notas.length]; //guarda o numero de repetições de cada item
  76.  
  77. for (int i = 0; i < notas.length; i++) {
  78. for (int j = 0; j < notas.length; j++) {
  79. if (j != i)
  80. if (notas[i] == notas[j]) numeroRepeticoes[i]++;
  81. }
  82.  
  83. }
  84.  
  85. return numeroRepeticoes;
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement