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.
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);
}
}
+ 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);}
}
}
+ 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
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!