1

Not sure where I'm going wrong with this. I've asked someone in my class and they said there should be an argument with "toonRijSterren". when I do this I just get more errors, could someone have a look and tell me where I'm going wrong?

public static void main(String[] args) {

    int aantal = 0;
    toonRijSterren(aantal);
    toonSterrenVierkant(aantal);
}

public static void toonRijSterren(int mpAantal) {
    while (mpAantal < 6) {
        System.out.print(" * ");
        mpAantal++;
    }
}

public static void toonSterrenVierkant(int mpAantal) {
    for (int mpAatal = 0; mpAantal < 6; mpAantal++) {
        System.out.println(toonRijSterren());
    }
}

ther error line is in the brackets of the last toonRijSterren());

5 Answers5

0

You are not passing the argument when you call your method.

Try this:

System.out.println(toonRijSterren(mpAatal));
  • Thanks for the reply! but when i do that i keep getting error statements saying add braces to for, and when i correct that it tells me to get rid of them again :/ – Adzor Verhaagen Apr 19 '20 at 17:04
  • Like @yon264 says, you are not returning an integer value when you call your method `toonRijSterren(mpAantal)`. In your `toonSterrenVierkant() ` method, change the `System.out.println(toonRijSterren(mpAatal));` to `toonRijSterren(mpAatal);` – Kaushik Awala Apr 19 '20 at 17:38
0

You are missing the parameter in your toonSterrenVierkant() function where you calling toonRijSterren.

Here is the corrected version of your code:

public static void toonSterrenVierkant(int mpAantal) { 
  for (; mpAantal < 6; mpAantal++) { 
    toonRijSterren(mpAatal); 
  } 
}
famabenda
  • 80
  • 1
  • 13
  • When i do that i keep getting error statements saying add braces to for, and when i correct that it tells me to get rid of them again :/ – Adzor Verhaagen Apr 19 '20 at 17:02
  • It seems you have a general problem with the braces in your class. Check if there is an closing brace for every opening and check if they are in the right places – famabenda Apr 19 '20 at 17:04
0

First of all, your function toonRijSterren takes an int type parameter (according to its declaration), so you need to pass to it another argument. For example: toonRijSterren(mpAantal)

Second, the function toonRijSterren returns void. That means, it just does an operation (in this case, printing) without returning anything. What you're trying to do is to use its return value (which doesn't exist) as an argument to System.out.println, which causes an error (because println expects an argument of some type). You could achieve what I think you're trying to do with the line: toonRijSterren(mpAantal);. The function itself prints the values, so the println here is unnecessary and causes an error.

YonPog
  • 19
  • 2
0
  1. toonRijSterren is void method which means it does not return any value and therefore you can not put it inside System.out.println() or you can not assign it to some variable.
  2. toonRijSterren expects an int argument which you have missed while calling it.

Given below is an example of how you should call toonRijSterren:

public static void toonSterrenVierkant(int mpAantal) {
    for (int mpAatal = 0; mpAatal < 6; mpAatal++) {
        toonRijSterren(mpAantal);
    }
}
Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
0

As your methed toonSterrenVierkant(int mpAantal) has a int parameter, you must pass an int value as an argument in the last toonRijSterren(). For example, replace the line System.out.println(toonRijSterren()); with System.out.println(toonRijSterren(1));

Zain
  • 37,492
  • 7
  • 60
  • 84