I have figured out how to do this. All that is needed is the .useDelimeter error. help?

import java.io.*;
import java.util.*;
public class AddEmUp{public static void main(String args[])
`Scanner sc = new Scanner(System.in);

System.out.print("Enter something like 8 + 33 + 1,345 - 137 : ");String s = sc.nextLine();


 `s = "+" + s;

Scanner sc1=new Scanner(s);sc1.useDelimeter("\s\+\s|\s-\s");

`int sum = 0;



   `sum = sum + sc1/nextInt();


Scanner sc2 = new Scanner(s);sc2.useDelimeter("\s\+\s|\s-\s");



   `sum=sum - sc2.nextInt();

System.out.println("Sum is: " +sum);}}`

Literal \ characters in Java Strings need to be "escaped" - ie replaced with a double \
You did that in the findInLine, but not in your useDelimiter

Edited 2 Years Ago by JamesCherrill

It must not have posted correctly. In my code that i have on my computer i have a double \ in the useDelimeter

OK, in that case, after another look I can see the problem. Check the API documentation for Scanner, you have mis-spelled the name of the method.
Next time please post (copy/paste) the complete text of your error message(s) - that would have enabled me to identify the fault immediately.

I have tried to mark it solved. I believe that my computer will not let me mark it.

Its the pale blue button "Mark Question Solved" just below the entry field for submitting a reply, which is just below this message.

Edited 2 Years Ago by JamesCherrill

This question has already been answered. Start a new discussion instead.