Java - CREAR PROGRAMA EN CONSOLA

 
Vista:

CREAR PROGRAMA EN CONSOLA

Publicado por yeni cardona (2 intervenciones) el 01/05/2014 02:56:04
Escribe un programa que lea de consola, 10 enteros y los escriba en el archivo “salida1.txt”.

2. Escribe un programa que lea del archivo “salida1.txt” los 10 números enteros; los eleve al cuadrado, y guarde los resultados en “salida2.txt”.

3. Escribe un programa que lea del archivo “salida2.txt” los 10 números enteros y los despliegue en pantalla.

4. Escribe un programa que lea el nombre y la edad del estudiante hasta que el usuario ingrese el 0 y los almacene en el archivo "estudiantes.txt"

5. Genera un archivo plano con los códigos de 20 estudiantes delimitado por comas.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

CREAR PROGRAMA EN CONSOLA

Publicado por Mario (26 intervenciones) el 02/05/2014 03:39:16
Cuál es tu duda?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

CREAR PROGRAMA EN CONSOLA

Publicado por yeni cardona (2 intervenciones) el 02/05/2014 05:41:29
tengo las tres clases creadas, ejercicio 1, ejercicio 2 y el archivo :
1
2
3
4
5
6
7
8
9
10
11
12
package textos;
 
public class Ejercicio1 {
/*
 * Escribe un programa que lea de consola, 10 enteros y los escriba en el archivo “salida1.txt”
 * */
	public static void main(String[] args) {
Archivo a = new Archivo();
a.escribir("salida1.txt");
 
	}
}
pero el punto 2 no me muestra lo qe necesito ni lee del archivo 1 los enteros para elevarlos al cuadrado...
esto es lo q tengo del ejercicio 2
1
2
3
4
5
6
7
8
9
10
11
package textos;
 
public class Ejercicio2 {
 
	public static void main(String[] args) {
 
		Archivo a = new Archivo();
		a.doblar("salida2.txt");
 
	}
}

y esto del archivo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package textos;
import java.io.*;
 
import javax.swing.*;
public class Archivo {
 
public void doblar( String nombreArchivo){
	File f; // crea objeto tipo arhivo
	f = new File("salida2.txt"); // se asigna el nombre del archivo
 
 
	String temp="",c;
 
	/* Escribir en salida2*/
try{
	int a,i;
int[] b = new int[10];
FileWriter w = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(w);
PrintWriter wr = new PrintWriter(bw);
 
	FileReader r= new FileReader("salida1.txt");
	BufferedReader buffer= new BufferedReader(r);
	for(i =0;i<10;i++){
	temp = buffer.readLine();
		a=Integer.parseInt(temp);
		b[i]=a*a;
		if (temp==null){break;}
 
	}
 
 
c=Integer.toString(b[0])+"\n"+Integer.toString(b[1])+"\n"+Integer.toString(b[2])+"\n"+
Integer.toString(b[3])+"\n"+Integer.toString(b[4])+"\n"+Integer.toString(b[5])+"\n"+
Integer.toString(b[6])+"\n"+Integer.toString(b[7])+"\n"+Integer.toString(b[8])+"\n"+
Integer.toString(b[9])+"\n";
 
 
wr.write(c);
wr.close();
bw.close();
 
}catch(Exception e){}
 
}
public void escribir(String nombreArchivo){
	File f; // crea objeto tipo arhivo
	f = new File(nombreArchivo);
 
	try {
		int i;
		String a;
		FileWriter w = new FileWriter(f);
		BufferedWriter bw = new BufferedWriter(w);
		PrintWriter wr = new PrintWriter(bw);
 
		for (i=0;i<10;i++){
		a=JOptionPane.showInputDialog("Digite el numero en la posicion ["+i+"]");
			wr.write(a); //insertar valor
		wr.append("\n"); //concaternar al valor anterior
		}
 
 
		wr.close();
		bw.close();
	}catch(Exception e){}
}
 
} //fin clase
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar