Exercise8_18.java:11: cannot find symbol
symbol : variable str
Java cannot find a declaration for the variable "str" - it has not been declared.
You did however declare a string "s" and you saved the user input in it.
public class Exercise8_18 {
/**Main method*/
public static void main(String[] args) {
// Receive text entered from the dialog box
// Save it in local variable "s".
String s = JOptionPane.showInputDialog("Enter a sentence " +
"using punctuation:");
String delims = "[\\s\\p{Punct}]+";
// Split the String "s":
String[] tokens = s.split(delims);
System.out.println("The extracted words are: " +
java.util.Arrays.toString(tokens));