Method Calling Issues Java -



Method Calling Issues Java -

so i'm trying phone call method displayboard in java displays boardgame 1 time user enters in number in main method. i'm unable phone call method. see i'm going wrong or how prepare this? thanks.

public static void displayboard(int [] board, boolean showitem) { system.out.println(); system.out.print("_"); (int val : board){ switch(codes){ case 2: system.out.print("x"); break; case 3: system.out.print(" "); break; case 4: system.out.print(showitem ? "y" : " "); break; } system.out.print("_"); } //for system.out.println(); system.out.println(); }//display public static void main (string [] args) { int guess = 0; int userinput = promptforint("length of board"); int [] numbers = new int[userinput]; int randomlocs = new random().nextint(userinput); int val; int display = displayboard(board [], boolean showitem) // doesnt work? boolean showitem = false; while(! showitem) { val = promptforint("try again!"); if(guess == randomlocation) { system.out.println("found it!"); showitem = true; } else if(guess != randomlocs) system.out.print(val); } }

problem

you must pass values method call. right now, passing declarations method, isn't proper java syntax

how fix

first, declare showitem boolean before phone call method have boolean pass method. should this:

boolean showitem = false; int display = displayboard(numbers, showitem)

this pass vakues stored in numbers , showitem variables. know values stored in these specific variables (numbers , showitem) should passed in due method's parameter names.

the statements leading method phone call should this:

int userinput = promptforint("length of board"); int [] numbers = new int[userinput]; boolean showitem = false; int display = displayboard(board [], boolean showitem); int randomlocs = new random().nextint(userinput); //since isn't used before method call, should declared below int guess = 0; //same int val; //and

java

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -