 <p>The variable <code>more</code> is only in scope inside the do while loop. One solution would be to declare more outside the loop and only update its value inside.</p> <p>Like this...</p> <pre><code>public static void main(String[] args) { Scanner input = new Scanner(System.in); String cont = "y"; String more = null; do { . .// code here . System.out.println("Do you want to continue?"); more = input.next(); } while (more.equals(cont)); </code></pre> <p>This happens because any variable which is declared inside a do-while construct is only in scope within that same loop, it cannot be accessed outside the loop, or in the loop condition.</p> <p>Declaring the variable outside the loop and within main gives access to the variable anywhere inside the main method.</p>