cant we create a scanner class object inside the method ?? whats the purose of passing it into the method as an argument??
Why are we passing the Scanner object into the method argument.?
Hey @syedfaisaljaved
You can create a global Scanner object also and also use that normally in all the functions of program.
public static Scanner scn = new Scanner(System.in);
Please share the links of problem and code if you have doubt in some particular question…
In binaryTree for setting the input we have passed the scanner object as an argument in the takeinput function. What is the purpose of doing that.
There also you can do it both ways- either by passing the scanner as is done or by creating it globally then you need not pass it as the arguement. Both ways work fine.