Start New Discussion within our Software Development Community

Hi I am having some problem understanding the do-while loop in the following program, and I was hoping for some help:

import static java.lang.System.out;
import java.util.Scanner;

class DeleteEvidence {

   public static void main(String args[]) {
      File evidence = new File("c:\\cookedBooks.txt");
      Scanner keyboard = new Scanner(;
      char reply;

      do {
         out.print("Delete evidence? (y/n) ");
         reply = 
      } while (reply != 'y' && reply != 'n');

      if (reply == 'y') {
         out.println("Okay, here goes...");
         out.println("The evidence has been deleted.");
      } else {
         out.println("Sorry, buddy. Just asking.");

Basically I know how the do-while loop works, as in it executes one time and then checks the conditions. In here the condition is while (reply != 'y' && reply != 'n'); and this is throwing me a little: so we want the program to display this out.print("Delete evidence? (y/n) "); only when the answer is not 'y' and not 'n'? Am I understanding this correctly?

no. you'll show that line at least once (the first iteration)
I'm not sure why you're going for "findWithinHorizon", you could also have gone for next or nextLine, and just read the first char.

personally, I would advice against this book.
if you are just starting out with java, you shouldn't use an IDE (yet). first get familliar with coding in notepad, and compiling, packaging and running your applications through command prompt.

I've gone over the "contents" a bit ... Very little, and not the best choice.
I would rather recommend Deitel & Deitel's Java, how to program
or Ivor Horton's Beginning Java - Java 7 Edition

thanks, is there a guide somewhere on how to do that with the command prompt (I use linux)?
Also, the deitel and deitel book you recommended, is it easy to understand even for somebody who has never done any coding before?

This article has been dead for over six months. Start a new discussion instead.