Está en la página 1de 1

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package manejoficheros;
import java.io.*;
public class Demo4
{
public static void main(String[] args)
{
FileWriter fichero = null;
PrintWriter pw = null;
int sumax=0;
int sumay=0;
int cont1=5;
int cont2=10;
int cont3=15;
try
{
fichero = new FileWriter("C:/EjemplosArchivos/prueba4.txt");
//fichero = new FileWriter("prueba.txt");
pw = new PrintWriter(fichero);
pw.printf("\nMi Archivo tiene lo siguiente\n");
while ( cont1 < 106)
{
pw.printf("\n %d " , cont1);
cont1=cont1+1;
pw.printf(" %d " , cont2);
cont2=cont2+2;
pw.printf(" %d " , cont3);
cont3=cont3+3;
sumax=sumax+cont2;
sumay=sumay+cont3;
}
pw.printf("\nla sumax es: %d la sumay es : %d", sumax, sumay);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
// Nuevamente aprovechamos el finally para
// asegurarnos que se cierra el fichero.
if (null != fichero)
fichero.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}

También podría gustarte