![]() ![]() Since you haven't learned about arrays yet and are working with a Scanner with a delimiter pattern, we'll have to work around this constraint.įirst, for the purposes of a school assignment, we can probably safely assume that your inputs will follow a particular pattern, along the lines of: (number)(operator)(number)(operator)(number). I'm going to help you answer this in a way that's (hopefully) consistent with what you've learned so far. Now we convert the String to a scanner because we will be using Scanner methodsĬan anybody help me solve the problem (First comment in my source code)? Here is my source code: //I can't get it to work if I use subtraction and addition at the same time but they work separately Now modify the program as to allow either plus or minus signs a minus sign surrounded by any amount of white space. Set delimiters to a plus sign surrounded by any amount of white space.or. object otherwise, it can get stuck waiting for input. ![]() String s = kb.nextLine( ) //Best to store in a String and then create a new Scanner ![]() So my teacher gave me an assignment to do (will be shown below) and I tried to do it but just could not figure it out, here's the assignment:Ĭonsider the following program that allows something like 8 + 33 + 1,345 + 137 to be entered as String input from the keyboard, A Scanner object then uses the plus signs (and any adjoining white space) as delimiters and produces the sum of these numbers (1523). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |