# Values of elements using regular expression

• 10-24-2011, 02:32 PM
Dimitri
Values of elements using regular expression

File in.properties (pairs key=value) contains some sequence of lines.
Let the element with key indexi has the value j (i=1..n, j=1..m – natural numbers without leading zeros). It determines the index of an element with name valueij (j = indexi) you should work with.
1) Print the sum of values of elements, having the key valueij (see examples below).
2) Print the number of index elements with “errors” (i, j – unnatural numbers; no correct value-element for sum).

The example of the file in.properties:
index1 = 3
value11=qw
value12=4
value13 = 5.1
value14=2.7
index2=15
value21=
value22=
value23=
value24=k
value25=5
index3=1
value31= 3.14
value32=fgh
value33=5
index4=0
value41=
value42=e1
value43=2
value44=3
index5=b
value51=d
value52=e

Output:
sum = 8.24
error-lines = 3

I read from a file as follows:

Code:

```ResourceBundle rb = ResourceBundle.getBundle("in"); Enumeration<String> keys = rb.getKeys(); String key; while(keys.hasMoreElements()) {  key = keys.nextElement();  ... }```
How now?
I cant do the third day. Please, help!

P.S. Sorry for my english
• 10-24-2011, 03:31 PM
Dimitri
Re: Values of elements using regular expression