View the step-by-step solution to:

Problem 4 Reading and Parsing Java String The Java String class defines the following method to split a Java String object into multiple fragments of...

Problem 4 Reading and Parsing Java String

The Java String class defines the following method to split a Java String object into multiple fragments of substrings and store them in a returned String array:

String[] split( String regularExpression)

The regularExpression argument specifies a delimiter or separator pattern. More detailed information can be found in the Java Document API (http://java.sun.com/javase/6/docs/api/). The following example uses “-“ as a separator to split a String object:

String initialString = “1:one-2:two-3:three”;
String[] fragments = initialString.split(“-“);

The resulting fragments array contains three Strings of “1:one”, “2:two”, and “3:three”. One can further split these fragments if needed. For example,

String[] pair1 = fragments[0].split(“:”);

The pair1 array contains two String objects of “1” and “one”.

Given the following line in a text file:

A=Excellent B=Good C=Adequate D=Marginal E=Unacceptable

Write a method that would read this text file and print out the followings:

Grade A is Excellent
Grade B is Good
Grade C is Adequate
Grade D is Marginal
Grade E is Unacceptable

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question