Welcome to the Ranch
Please use the
code button for code; since you are new I shall go and use the code button on your post, and you can see how much better it looks
I am afraid I don't like the design of that method. Why are you using that
boolean? Were you told to? And why have you given it an uninformative name like
flag? Can you divide that method into two? Agree with Carey; you should make such methods
static.
Please explain what the method is supposed to do.
You have to become very precise about nomenclature; I can see nothing that would “throw a runtime error.” That would mean an exception and nothing in that method can throw an exception. I think the method is written incorrectly and you are getting results different from what you wanted.
Never write
== true nor
== false which are poor style and very error‑prone. If you write
= true nor
= false by mistake you will get two errors (or more) for the price of one. Did I say, “if”? I meant, “when”.
Never
if (b == true) ... please. Always
if (b) ... please.
Never
if (b == false) ... please. Always
if (!b) ... please.