1. Write a program which creates a file with all the numbers from 1 to 100.
2. Read this file. Separate the odd numbers from even numbers and write the odd numbers to a new file called odd.dat, even numbers to even.dat.
3. Read the odd.dat file, total all the numbers which are divisible by 3, find the average of these numbers and append to end of this file.
So far I manage to create a file and read it from it but I cannot separate it properly
package javaapplication34; import java.util.Scanner; import java.io.*; public class JavaApplication34 { public static void main(String[] args)throws IOException { int number=0; Scanner keyboard = new Scanner(System.in); PrintWriter nm=new PrintWriter("number.txt"); PrintWriter odd=new PrintWriter("odd.txt"); PrintWriter even=new PrintWriter("even.txt"); do { nm.println(number); number++; }while(number<101); nm.close(); // Get the filename. System.out.print("Enter the filename: "); String filename = keyboard.nextLine(); // Open the file. File file = new File(filename); Scanner inputFile = new Scanner(file); // Read lines from the file until no more are left. while (inputFile.hasNext()) { // Read the next name. String friendName = inputFile.nextLine(); if (number%2==0){ even.println(number); } else{ odd.println(number); } // Display the last name read. System.out.println(friendName); } // Close the file. even.close(); odd.close(); inputFile.close(); // TODO code application logic here } }