Advertisement
veto14

vetordechar.java

Sep 12th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class tochar {
  4. public static void main (String []args) {
  5. int nv,np;
  6. Scanner sc = new Scanner(System.in);
  7. String f = sc.nextLine();
  8. sc.close();
  9. vetordechar v = new vetordechar(f);
  10. v.imprimevetor(v);
  11. nv = v.nvogais(v);
  12. np = v.npal(f, v);
  13. System.out.println("O numero de vogais na sua String é: " + nv);
  14. System.out.println("O numero de palavras repetidas na sua String é: " + np);
  15. }
  16. }
  17.  
  18. class vetordechar{
  19. char[] vetc;
  20. vetordechar(String f){
  21. vetc = f.toCharArray();
  22. }
  23. void imprimevetor(vetordechar v){
  24. for(int i=0; i<v.vetc.length; i++) {
  25. System.out.print(v.vetc[i]);
  26. }
  27. System.out.println(" ");
  28. }
  29.  
  30. int nvogais(vetordechar v) {
  31. int cont = 0;
  32. for(int i=0; i<v.vetc.length; i++) {
  33. if(v.vetc[i] == 'a' || v.vetc[i] == 'A' || v.vetc[i] == 'e' || v.vetc[i] == 'E' || v.vetc[i] == 'i' || v.vetc[i] == 'I' || v.vetc[i] == 'o'|| v.vetc[i] == 'O' || v.vetc[i] == 'u' || v.vetc[i] == 'U') {
  34. cont++;
  35. }
  36. }
  37. return cont;
  38. }
  39.  
  40. int npal(String f, vetordechar v) {
  41. int espacos = 1;
  42. int pals = 0;
  43. for(int i=0; i<v.vetc.length; i++) {
  44. if(v.vetc[i] == ' ') {
  45. espacos++;
  46. }
  47. }
  48. String[] palavras = new String[espacos];
  49. palavras = f.split(" ");
  50. for(int i=0; i<espacos; i++) {
  51. for(int j=0; j<espacos; j++) {
  52. if(palavras[i] == palavras[j]) {
  53. pals++;
  54. }
  55. }
  56. }
  57. return pals;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement