I'm trying to write a file that first decides if a number entered is prime or not, then if it is writes it to a file. Here's what I've got, but I keep coming up with a couple errors that I can't figure out how to fix. One is that I can't figure out how to bring the number into the second method (which I have to use). I'm also not sure I'm using the write way to write to file. Help?
import java.io.*;
import. java.util.Scanner;
int num;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a positive integer: ");
num = keyboard.nextInt();
for (int x=2; x < num; x++)
{
if (num%x==0)
noPrime();
else
prime();
}
System.exit(0);
}
public static void prime(int num)
{
System.out.println(num + " is prime.");
while (num <=100 && num >=1);
{
//Open the file.
PrintWriter outputFile = new PrintWriter(PrimeNumbers.txt);
//Write number to the file.
outputFile.println(PrimeNumbers.txt);
//Close the file.
outputFile.close();
System.out.println("Numbers written to file.");
}
}
public static void noPrime(int num)
{
System.out.println(num + " is not prime.");
}
}//end class