Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ar.edu.unju.Punto05;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.util.LinkedList;
- public class leerTexto {
- int cont = 0;
- private static LinkedList<String> arregloPar = new LinkedList<String>();
- private static LinkedList<String> arregloImpar = new LinkedList<String>();
- public String read_text(String texto) {
- try {
- BufferedReader bf = new BufferedReader(new FileReader("C:\\Users\\Arias\\Documents\\FER\\txt\\TP02Frase.txt"));
- String temp = "";
- String bfRead;
- while((bfRead = bf.readLine()) != null) {
- temp = temp + bfRead +" ";
- if (cont % 2 == 0) {
- arregloPar.add(bfRead);
- }else {
- arregloImpar.add(bfRead);
- }
- cont ++;
- }
- texto = temp;
- } catch (Exception e) {
- // TODO: handle exception
- System.err.println("No se encontro archivo.");
- }
- return texto;
- }
- public void intercambiar_lineas() {
- try {
- File archivo = new File("C:\\Users\\Arias\\Documents\\FER\\txt\\TP02FraseCambiada.txt");
- BufferedWriter bw;
- bw = new BufferedWriter(new FileWriter(archivo));
- do {
- if(!arregloImpar.isEmpty()) {
- bw.write(arregloImpar.pop());
- bw.newLine();
- }
- if(!arregloPar.isEmpty()) {
- bw.write(arregloPar.pop());
- bw.newLine();
- }
- }while(!arregloPar.isEmpty()||!arregloImpar.isEmpty());
- bw.close();
- } catch (Exception e) {
- // TODO: handle exception
- System.err.println("No se puedo escribir el archivo.");
- }
- }
- public void cont_lineas() {
- System.out.println("La cantidad de lineas es: "+cont);
- }
- }
- ---------------------------------------------------------------------------------------------------------
- package ar.edu.unju.Punto05;
- import java.util.StringTokenizer;
- public class Archivos {
- public static void main(String[] args) {
- leerTexto a = new leerTexto();
- String texto = "";
- texto = a.read_text(texto);
- System.out.println(texto);
- contar_vocales(texto);
- espacios_blancos(texto);
- cant_palabras(texto);
- cant_mayusculas(texto);
- a.cont_lineas();
- a.intercambiar_lineas();
- }
- public static void cant_palabras(String texto) {
- StringTokenizer st = new StringTokenizer(texto);
- System.out.println("La cantidad de palabras es: "+st.countTokens());
- }
- public static void cant_mayusculas(String texto) {
- int cont = 0;
- for(int i=0; i<texto.length(); i++) {
- char temp = texto.charAt(i);
- char mayus = Character.toUpperCase(temp);
- if((mayus == temp) && (mayus != ' ')){
- cont++;
- }
- }
- System.out.println("La cantidad de mayusuclas es: " + cont);
- }
- public static void espacios_blancos(String texto) {
- int cont_espacios = 0;
- for(int i=0; i<texto.length(); i++) {
- char temp = texto.charAt(i);
- if(temp == ' '){
- cont_espacios++;
- }
- }
- System.out.println("La cantidad de espacios en blanco es: "+(cont_espacios-1));
- }
- public static void contar_vocales(String texto) {
- int contVocales = 0;
- for(int i=0; i<texto.length(); i++) {
- char temp = texto.charAt(i);
- if(temp == 'a' || temp =='A') {
- contVocales ++;
- }else if(temp == 'e' || temp =='E') {
- contVocales ++;
- }else if(temp == 'i' || temp =='I') {
- contVocales ++;
- }else if(temp == 'o' || temp =='O') {
- contVocales ++;
- }else if(temp == 'u' || temp =='U') {
- contVocales ++;
- }
- }
- System.out.println("La cantidad de vocales que tiene el texto es: "+contVocales);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement