Practice Makes Perfect java practice | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Practice Makes Perfect java practice

I keep getting the ā€œCannot find symbolā€ error. Any and all assistance in figuring out whatā€™s missing or wrong with my code is appreciated. Thanks! Code will be in the next comment.

7th Jul 2021, 10:51 PM
Jon Scoggins
Jon Scoggins - avatar
4 Respostas
+ 5
import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[ ] args) { Scanner scanner = new Scanner(System.in); LinkedList<String> words = new LinkedList<String>(); while(words.size()<5){ String word = scanner.nextLine(); //add the word to LinkedList words.add(word);} //your code goes here for(String s:words) if(s.length()==4) System.out.println(s); } }
7th Jul 2021, 11:53 PM
Ciro Pellegrino
Ciro Pellegrino - avatar
+ 1
The program you are given declares LinkedList "words". Write a program to take words as input and add them to LinkedList untill its size isn't equal to 5, then output only those words whose length is more than 4 characters. Sample Input Java practice is makes perfect Sample Output practice makes perfect import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[ ] args) { Scanner scanner = new Scanner(System.in); LinkedList<String> words = new LinkedList<String>(); while(words.size()<5){ String word = scanner.nextLine(); //add the word to LinkedList words.add(word);} //your code goes here if(words.length(word)>4){ System.out.println(word);} } }
7th Jul 2021, 10:51 PM
Jon Scoggins
Jon Scoggins - avatar
+ 1
word is not defined in the scope. It's a local variable in the while block the length method is not defined in LinkedList class
7th Jul 2021, 11:43 PM
Ciro Pellegrino
Ciro Pellegrino - avatar
0
I thought it might have something to do with the for loop but didnā€™t get the code right earlier. Itā€™s good now. Thanks for the assist, Ciro! Have a good day!
8th Jul 2021, 12:00 AM
Jon Scoggins
Jon Scoggins - avatar