Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that reads a line of text input by the user and places each word in a TreeSet. Print the elements of the

Write a program that reads a line of text input by the user and places each word in a TreeSet. Print the elements of the TreeSet to the screen. This will cause the elements to be printed in ascending order. Include your name at the top of your source file. Use proper indentation, like you see in the book. Your class must be in a package named mypackage, as explained in last week's videos and be named TreeSetUse. Upload TreeSetUse.java. This is my code:

import java.util.Scanner; import java.util.TreeSet; package mypackage;

public class TreeSetUse { public static void main(String[] args) { Scanner sc = new Scanner(System.in); TreeSet tree=new TreeSet(); System.out.println("Enter line: "); String str = sc.nextLine(); for (String s : str.split(" ")) tree.add(s); System.out.println(tree); } }

This is the error message I received:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: at mypackage.TreeSetUse.main(TreeSetUse.java:7)

Can someone help me understand how to resolve this?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

5. How will the members be held accountable?

Answered: 1 week ago