Linkedlist | Sololearn: Learn to code for FREE!

+3

Linkedlist

Anyone could tell me what I am making wrong in this code please ? 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 here is my try? https://code.sololearn.com/cA163A23A13a

5/22/2021 6:19:16 PM

フアンラモーネMH, ]

4 Answers

New Answer

+3

//Please Subscribe to My Youtube Channel //Channel Name: Fazal Tuts4U 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(); words.add(word); } for(String wordShow: words){ if(wordShow.length() <= 4){ }else{ System.out.println(wordShow); } } } }

+2

//your code goes here for(String w: words){ System.out.println(w.length()); } Here you are printing the length of each word. But you need to print w if w.length() > 4 So add a if statement inside the loop.

+1

thank you very much guys

0

You're printing word length instead print word if it's length is >=5 as for(String w: words) if(w.length()>=5) System.out.println(w);