example 1:
system.out.print("enter integer: "); int x = input.nextint(); if(x < value) { } example 2:
system.out.print("enter integer: "); if(input.nextint() < value) { } i have 2 questions:
which 1 better use if only need value in particular condition? or both syntaxes same in terms of memory?
whats happening entered value in 2nd example in terms of memory?
please want answers in detail.
the examples same in terms of memory because in both cases integer value put stack. however, 1st approach more convenient debugging because can observe value , change it.
see prev. it's allocated in stack.
besides, local variables recommended start lowercase, this: value.
Comments
Post a Comment