Logic Error using loop and array
Hi - the below code is attempting to loop through an array and print out any matching words if no matching words are found a message should be printed advising the user of this, however when no matching words are the message to the user is printing 6 times due to the for loop and when matching words are found the message is still printing once. I'm unsure how to change the below to get this working as required?
Word  ref = new Word ;
ref = new Word ("sad")
ref = new Word ("happy")
System.out.print("Please enter word: ");
word = scanner.nextLine();
for (int j = 0; j<2 ; j++)
System.out.printf("Word: = %-2s " , ref[j].getword()+ " ");
System.out.println("There are no matching words");
Re: Logic Error using loop and array
I do not really understand the purpose of your program. (Also put some points and commas in your sentences, it makes it easier to read.) And how can it print 6 times if you only have a loop of 2 runs and 2 printing options? Is this the entire code?