Advertisement
Guest User

ejercicio 6

a guest
Oct 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package tp03;
  2. import java.util.Scanner;
  3. import java.util.LinkedList;
  4. import java.util.Queue;
  5.  
  6. public class ejercicio06 {
  7.  
  8. public static void main(String[] args) {
  9. // TODO Auto-generated method stub
  10. Scanner teclado =new Scanner (System.in);
  11. Queue<Character> colaentrada= new LinkedList<Character>();
  12. Queue<Character> colasalida= new LinkedList<Character>();
  13. int contadorA=0, contadorE=0, contadorI=0, contadorO=0, contadorU=0;
  14. char respuesta='S';
  15.  
  16. do
  17. {
  18. System.out.println("Ingrese letras");
  19. char letra= teclado.next().charAt(0);
  20. colaentrada.add(letra);
  21. System.out.println("¿Desea seguir ingresando letras letras?");
  22. respuesta= teclado.next().charAt(0);
  23. } while (respuesta=='S' || respuesta=='s');
  24. System.out.println(colaentrada.toString());
  25. while (colaentrada.size()>0)
  26. {
  27. char elementocola= colaentrada.remove();
  28. if (elementocola=='a' || elementocola=='e' || elementocola=='i' || elementocola=='o' || elementocola=='u')
  29. {
  30. switch (elementocola)
  31. {
  32. case 'a': contadorA++;
  33. colasalida.add('A');
  34. break;
  35. case 'e': contadorE++;
  36. colasalida.add('E');
  37. break;
  38. case 'i': contadorI++;
  39. colasalida.add('I');
  40. break;
  41. case 'o': contadorO++;
  42. colasalida.add('O');
  43. break;
  44. case 'u': contadorU++;
  45. colasalida.add('U');
  46. break;
  47. }
  48. }
  49. else
  50. {
  51. colasalida.add(elementocola);
  52. }
  53. }
  54. System.out.println(colasalida.toString());
  55. System.out.println("Cantidad de A: "+ contadorA);
  56. System.out.println("Cantidad de E: "+ contadorE);
  57. System.out.println("Cantidad de I: "+ contadorI);
  58. System.out.println("Cantidad de O: "+ contadorO);
  59. System.out.println("Cantidad de U: "+ contadorU);
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement