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:
- [Solved] IDEA JSP File out.println Error: Cannot resolve method ‘println(java.lang.String)’
- [Solved] void value not ignored as it ought to be
- [Solved] The method getContextPath() from the type HttpServletRequest refers to the missing type String
- Abnormal [System.InvalidOperationException: custom type mapping for ‘xxx’ is not specified or is not a solution
- There was an unexpected error (type=Method Not Allowed, status=405). Request
- Go declares that the local variable does not use command line arguments. Main. Go: 4:6: a declared but not used
- [Solved] MindSpore Error: Data type conversion of ‘Parameter’ is not supporte
- [Solved] MongoDB Error: TypeError: Object of type ObjectId is not JSON serializable
- maven Error: Element ‘dependency’ cannot have character [children], because the type’s content type is
- std::dynamic_pointer_cast Error: source type is not polymorphic
- C++ Compile Error: error: invalid conversion from ‘void*‘ to ‘char*‘ [-fpermissive]
- How to Solve TypeError: type numpy.ndarray doesn’t define __round__ method
- How to Solve TypeError: type numpy.ndarray doesn‘t define __round__ method
- VUE: Property or method “deleteFun“ is not defined on the instance but referenced during render. [How to Fix]
- How to Solve Error: Element ‘dependency’ cannot have character [children], because the type’s content type is element-
- MOTR compiling error: cannot call member function ‘void std::basic_string<_CharT, _Traits, _Alloc>::_R
- C++ new types may not be defined in a return type Error?
- [Solved] HTTP Error 405.0-Method Not Allowed occurs in the Put operation of the REST service on IIS7.5
- [Solved] Error: The superclass, ‘Animal‘, has no unnamed constructor that takes no arguments.
- Libtorch Error: Expected object of type Variable but found type CUDALongType for argument #2 ‘index’