Advertisement
srwaan

atividade

Nov 12th, 2019
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. import java.nio.file.Files;
  2. import java.nio.file.Paths;
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.util.Scanner;
  6. public class SalvaArquivo {
  7.     public static void main (String [] args){
  8.         Scanner scanner = new Scanner (System.in);
  9.         System.out.print("Digite o texto: ");
  10.        
  11.         String texto = scanner.nextLine();
  12.         escreveArquivo(texto);
  13.         String textoLido = leArquivo();
  14.         contaVogais(textoLido);
  15.         scanner.close();
  16.         }
  17.     /*-*/
  18.     public static void escreveArquivo(String texto) {
  19.         System.out.println("Escrevendo no arquivo a string: " + texto);
  20.         try {
  21.             Files.write (Paths.get ("/Users/Aluno.SSA-D-CPIL01-11/Desktop/teste/teste.txt"), texto.getBytes());
  22.         } catch (Exception e){
  23.             System.out.println ("Erro: " + e);
  24.         }
  25.     }
  26.    
  27.     /*-*/
  28.     public static String leArquivo () {
  29.         System.out.println("Lendo arquivo: ");
  30.         String textoLido = null;
  31.         try {
  32.             FileReader fileReader = new FileReader("C:/Users/Aluno.SSA-D-CPIL01-11/Desktop/teste/teste.txt");
  33.             BufferedReader buffReader = new BufferedReader(fileReader);
  34.            
  35.             textoLido = buffReader.readLine();
  36.            
  37.         } catch (Exception e) {
  38.             System.out.println("Erro: " + e);
  39.         }
  40.         System.out.println(textoLido);
  41.         return textoLido;
  42.     }
  43.    
  44.     /*-*/
  45.     public static void contaVogais(String texto) {        
  46.         String textoCaps = texto.toUpperCase();
  47.         System.out.println (textoCaps);
  48.        
  49.         int vogais = 0;
  50.         for (int i = 0; i < textoCaps.length(); i ++) {
  51.             char c = textoCaps.charAt(i);
  52.             if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
  53.                 vogais ++;
  54.         }
  55.         System.out.println ("Quantidade de vogais: " + vogais);
  56.     }
  57.    
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement