Java Reference
In-Depth Information
38 if
(Character.isDigit(input.charAt(start)))
39 {
40 end = start + 1 ;
41 while (end < input.length()
42 &&
Character.isDigit(input.charAt(end)))
43 end++;
44 }
45 else
46 end = start + 1 ;
47 return r;
48 }
49
50 private String input;
51 private int start;
52 private int end;
53 }
616
617
ch13/expr/ExpressionCalculator.java
1 import java.util.Scanner;
2
3 /**
4 This program calculates the value of an expression
5 consisting of numbers, arithmetic
operators, and parentheses.
6 */
7 public class ExpressionCalculator
8 {
9 public static void main(String[] args)
10 {
11 Scanner in = new Scanner(System.in);
12 System.out.print( "Enter an expression:
" );
13 String input = in.nextLine();
14 Evaluator e = new Evaluator(input);
15 int value = e.getExpressionValue();
16 System.out.println(input + "=" + value);
17 }
18 }
Search WWH ::




Custom Search