Note that there are some explanatory texts on larger screens.

plurals
  1. POConstructor in class cannot be applied to given types
    primarykey
    data
    text
    <p>I ve got the following code using arrays to find some prim numbers. However, when trying to compile my user class PalindromeArrayUser it says - "Constructor in class cannot be applied to given types"</p> <p>required: int. found: no arguments. reason: actual and formal arguments lists differ in length.</p> <p>However, I have passed to the constructer an int value (the same way it was designed in my blueprint). I don't quite get where the problem comes from. Thanks. </p> <p>Here are my two classes </p> <pre><code> public class PalindromeArray { int arrLength; public PalindromeArray(int InputValue) { arrLength = InputValue; } int arr[] = new int[arrLength]; boolean check[] = new boolean [arrLength]; public void InitializeArray() { for (int k = 2; k &lt; arr.length; k++) { arr[k] = k; check[k] = true; } } public void primeCheck() { for (int i = 2; i &lt; Math.sqrt(arr.length - 1); i++ ) { if (check[i] == true) { for (int j = 2; j &lt; arr.length; j++) { if (j % i == 0) { check[j] = false; check[i] = true; } } } } } public void PrintArray() { for (int k = 2; k &lt; arr.length; k++) { if ((!check[k]) == false) System.out.println(arr[k]); } } } </code></pre> <p>And this is my User class where the problem comes from. The class above compiles fine.</p> <pre><code> import java.io.*; public class PalindromeArrayUser extends PalindromeArray { public static void main(String argv[]) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please enter the upper bound."); String line = input.readLine(); int InputUser = Integer.parseInt(line); // this is where I pass the same int type as I // constructed it PalindromeArray palindrome = new PalindromeArray(InputUser); palindrome.InitializeArray(); palindrome.primeCheck(); palindrome.PrintArray(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload