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

import java.io.File;
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(System.in);
      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?

4 Years
Discussion Span
Last Post by Violet_82

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?

Edited by Violet_82

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.