private String getWhoozitYs(){ StringBuffer sb = new StringBuffer(); boolean stop = generator.nextBoolean(); if(stop = true) { sb.append("y"); getWhoozitYs(); } return sb.toString(); }
This is a piece of code for a project that I am doing in a programming course. The problem I'm facing is that after declaring a logical stop and trying to assign it a randomly generated boolean, I cannot use it in an if statement to determine whether I add more y to the StringBuffer or not. I have a random number generator inside the constructor, so this part is not a problem. I suggested that since I declared a boolean outside the if statement, I could use it internally, but that doesn't seem to be the case. The real question is how can I use a random Boolean definition in an if statement.
java if-statement boolean
user2041920
source share