Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class tochar {
- public static void main (String []args) {
- int nv,np;
- Scanner sc = new Scanner(System.in);
- String f = sc.nextLine();
- sc.close();
- vetordechar v = new vetordechar(f);
- v.imprimevetor(v);
- nv = v.nvogais(v);
- np = v.npal(f, v);
- System.out.println("O numero de vogais na sua String é: " + nv);
- System.out.println("O numero de palavras repetidas na sua String é: " + np);
- }
- }
- class vetordechar{
- char[] vetc;
- vetordechar(String f){
- vetc = f.toCharArray();
- }
- void imprimevetor(vetordechar v){
- for(int i=0; i<v.vetc.length; i++) {
- System.out.print(v.vetc[i]);
- }
- System.out.println(" ");
- }
- int nvogais(vetordechar v) {
- int cont = 0;
- for(int i=0; i<v.vetc.length; i++) {
- 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') {
- cont++;
- }
- }
- return cont;
- }
- int npal(String f, vetordechar v) {
- int espacos = 1;
- int pals = 0;
- for(int i=0; i<v.vetc.length; i++) {
- if(v.vetc[i] == ' ') {
- espacos++;
- }
- }
- String[] palavras = new String[espacos];
- palavras = f.split(" ");
- for(int i=0; i<espacos; i++) {
- for(int j=0; j<espacos; j++) {
- if(palavras[i] == palavras[j]) {
- pals++;
- }
- }
- }
- return pals;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement