Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- There are 2 occurrences of Rose!
- There are 1 occurrences of Daffodil!
- There is a Rose!
- There is a Rose!
- There is a Daffodil!
- public void find2(String searchName){
- Node theNode = firstNode;
- int occurrences = 0;
- if(!isEmpty()){
- while (theNode.getItem().getName() != searchName){
- if (theNode.getItem().getName().equals(searchName)){
- occurrences++;
- }
- else if (theNode.getNext() == null){
- System.out.println("Flower not found!");
- return;
- }
- theNode = theNode.getNext();
- }
- System.out.println("Found " + occurrences + " occurrences of " + searchName + ".");
- }
- }
- else if (theNode.getNext() == null && occurrences == 0){
- System.out.println("Flower not found!");
- return null;
- }
- Exception in thread "main" java.lang.NullPointerException
- at LinkedList.find2(LinkedList.java:69)
- at FinalProject.searchFlowers(FinalProject.java:81)
- at FinalProject.<init>(FinalProject.java:37)
- at FinalProject.main(FinalProject.java:10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement