-2
Given an input file, generate an output file as shown below
Arquivo de Entrada | Arquivo de Saida
--------------------+--------------------
1 | impar
2 | par
3 | impar
4 | par
5 | impar
6 | par
I was only able to read the txt file and separate the pairs from the odd wanted to know how to create output file with odd pair, odd etc without having to separate them
import java.io.BufferedReader;
import java.io.FileReader;
public class Questao1
{
public static void main(String [] args) {
try
{
FileReader arquivo = new FileReader("Entrada1.txt");
BufferedReader leitor = new BufferedReader(arquivo);
String linha = leitor.readLine();
String pares = "";
String impares = "";
while (linha != null)
{
int numero = Integer.parseInt(linha);
if (numero % 2 == 0){
pares += numero + "\n";
} else{
impares += numero + "\n";
}
linha = leitor.readLine();
}
leitor.close();
System.out.println(pares);
System.out.println(impares);
}
catch (Exception ex) {
System.err.print(ex.getMessage());
}
}
}