You are viewing a single comment's thread. Return to all comments →
I tried doing it that way but it went wrong, so I had to take the:
Scanner scan = new Scanner(System.in);
B = scan.nextInt();
H = scan.nextInt();
out of the block.
Why is it?
No You can't do that because we need to reference the variables in main method,as main method is non-editable.so the only option you have that while compiling, when JVM loads (.class) file in the memory intialize all those variables at the same time that can be done when you declare variables as static.
Thanks, that helps a lot to understand how it works