Resolved: How Can I Use Scanner In Variable Returning Method? 0 By Isaac Tonny on 17/06/2022 Issue Share Facebook Twitter LinkedIn Question: I can’t get input from a user in variable returning method. What should I do? Here is example: public static void main(String[] args) { Scanner input = new Scanner(System.in); ... ... ... ... int[] which = new int[numberOfSlots]; for(int i = 0; i < numberOfBalls; i++){ which[leftOrRight(numberOfSlots);]++; } } public static int leftOrRight(int numberOfSlots, int numberOfBalls) { Scanner input = new Scanner(System.in); //I see red warring lamp left side of the line int gap = numberOfSlots/2; //I see red warring lamp left side of the line for(int i = 0; i < numberOfBalls; i++){ char input = input.next(); } return gap; } } [/code] Answer: Would be useful to know what the warnings say. Other than that, couple of things: This line [code]which[leftOrRight(numberOfSlots);]++; should be which[leftOrRight(numberOfSlots, numberOfBalls)]++; You can also just pass in the Scanner as a parameter instead of making a new one. If you have better answer, please add a comment about this, thank you! java java.util.scanner methods