Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. public static int calculate(String input){
  2. int lhs,rhs; //short for left-hand & right-hand side
  3. char operation;
  4. Scanner scanner = new Scanner(input);
  5. lhs = scanner.nextInt();
  6. while(scanner.hasNext()) {
  7. operation = scanner.next().charAt(0);
  8. rhs = scanner.nextInt();
  9. lhs = lhs + operation + rhs;
  10. System.out.println(lhs);
  11.  
  12. }
  13.  
  14.  
  15.  
  16.  
  17.  
  18. /*todo: your name and code goes here*/
  19. /*You need a Scanner(or StringTokenizer) to get tokens
  20. *Then you need a loop, and switch inside that loop*/
  21. return lhs;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement