id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

amjadm@miamioh.edu > buildNumber
prev  |  next  |  chance

calculate the result based on the given expression. The instruction contains numbers followed by operators e.g. "1+2-4*2+1/2*2". Return the result of the given string as an int (acceptable operators are + - * /). You need to parse the operations from left to right (rather than following standard order of operators in which some operators have priority over others). You can always assume there are at least one digit number and one operator inside the given string. The given string always starts with a digit and its length is always greater than 1. You can always assume all numbers are single-digit integers, and


buildNumber("9") → 9
buildNumber("1+2") → 3
buildNumber("2*2+3") → 7

...Save, Compile, Run (ctrl-enter)

public int buildNumber(String str) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 250 Post-solution available

Copyright Nick Parlante 2017 - privacy