I am calling the void method
printDivisors(inputNum)
and getting this error:
'void' type not allowed here
I concatenate the call to the method in a string and the compiler keeps complaining...
Here is the call to a method in a code:
if (determinePrime(inputNum)) {
JOptionPane.showMessageDialog(null, "Prime");
} else {
JOptionPane.showMessageDialog(null, "Not Prime" + printDivisors(inputNum));
}
Below you can see the full program:
import javax.swing.JOptionPane;
public class method_01 {
public static void main (String [] args) {
String input;
int inputNum;
// Determine Prime
do {
input = JOptionPane.showInputDialog("Enter a positive number please");
inputNum = Integer.parseInt(input);
} while (inputNum < 1 );
if (determinePrime(inputNum)) {
JOptionPane.showMessageDialog(null, "Prime");
} else {
JOptionPane.showMessageDialog(null, "Not Prime" + printDivisors(inputNum));
}
}
// Determine Prime Method
public static boolean determinePrime(int num) {
for (int i = 2; i < num ; i++) {
if (num % i == 0)
return false;
}
return true;
}
// Print all the divisors of a number
public static void printDivisors(int number) {
for (int i = 1; i <= number; i++ ) {
if (number % i == 0)
System.out.print("\t" + i);
}
}
}
Any help would be greatly appreciated.