java - I am getting an error on the 'start' in the (start + finish) at the bottom -
this question has answer here:
- scoping rules in java 3 answers
i getting error on 'start' in (start + finish) @ bottom. way fix add "int start = inputfn.nextint();" below ' scanner inputfn = new scanner(system.in);' screws up. able fix before forgot how did it. please help.
public static void main(string eth[]){ system.out.println("please enter integer:"); scanner inputfn = new scanner(system.in); if (inputfn.hasnextint()){ }else{ int start = inputfn.nextint(); system.out.print("play rules , enter integer"); } system.out.println("please enter integer:"); scanner inputsn = new scanner(system.in); int finish = inputsn.nextint(); int answer = (start + finish); system.out.println(answer); } }
the if
if (inputfn.hasnextint()){ }else{ int start = inputfn.nextint(); system.out.print("play rules , enter integer"); }
is kind of backwards. reading integer if there isn't one. , defining start variable inside if block why getting error.
something more like
int start = 0; if (inputfn.hasnextint()){ start = inputfn.nextint(); }else{ system.out.print("play rules , enter integer"); }
would seem better.
Comments
Post a Comment