Im trying to figure out why this simple piece of code isnt working.
The aim is for the user to enter a word and then the application echos the word back to them.
If the word is equal to 'done' then the application prints 'Complete'.

import java.util.*;
public class word
{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String word;
		String termination = "done";
		
		System.out.println("Enter the list of words, terminated by the word'done'");
		word = sc.next();
		
		while(!word.equalsIgnoreCase(termination));
		{	
			System.out.println(word);
			word = sc.next();
		}
		System.out.println("Complete");
	}
}

For some reason it doesnt work
Thanks

it doesnt work

Please explain what the code does. It doesn't work covers lots of cases.

Show the console from when you execute the code and add comments to explain what is not working.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

Fixed

import java.util.*;
public class word
{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String word;
		boolean isEqualTo;
		
		System.out.println("Enter the list of words, terminated by the word 'done'");
		word = sc.next();
		
		isEqualTo = word.equalsIgnoreCase("done");
				
		while(isEqualTo == false)
		{	
			System.out.println(word);
			word = sc.next();
			isEqualTo = word.equalsIgnoreCase("done");
		}
		
		System.out.println("Finished");
	}
}

You should explain what your problem was so the next student that reads this thread can learn from it.

the code worked fine but:

while(!word.equalsIgnoreCase(termination));

he should just have removed the ';' there.

I know, realised after debugging for ages. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.