The method println(boolean) in the type PrintStream is not applicable for the arguments (void) Error

Problem

An error occurred when I tried the following code.

public class PrimeFactorization {
	
	public static void primefactory(int m) {
		for (int i = 2; i < m; i++) {
			if (m % i == 0) {
				System.out.print(i+"*");
				m = m / i;
				i = 1;
				continue;
			}
			else if (i == (m-1)) {
				System.out.print(m);
			}
			else {
				continue;
			}
		}
	}
	
	public static void main(String[] args) {
		int k;
		System.out.println("Please enter the number to be decomposed into prime factors:");
		
		Scanner scanner = new Scanner(System.in);
		k = scanner.nextInt();
		
		System.out.print(k+" The result of decomposing the prime factors is"+primefactory(k));
		scanner.close();
	}
}

The error is line 27: the method println (Boolean) in the type printstream is not applicable for the arguments (void)

Solution

The return type of the primefactory() function in the program is “void”, which means that it is defined as having no return value. So instantiate the object PF in line 9 of the figure below, and call the primefactory() function through PF to make the program run smoothly.


	public static void main(String[] args) {
		int k;
		System.out.println("Please enter the number to be decomposed into prime factors.");
		
		Scanner scanner = new Scanner(System.in);
		k = scanner.nextInt();
		
		PrimeFactorization pf = new PrimeFactorization();
		System.out.print(k+" The result of decomposing the prime factors is");
		pf.primefactory(k);
		scanner.close();
	}
}

Read More: