Here is what I changed

Here is some of my output

run:

StackOverflowError

StackOverflowError

0's 1

1's 2

2's 3

3's 4

4's 5

5's 6

6's 7

7's 8

8's 9

9's 10

10's 11

11's 12

12's 13

13's 14

14's 15

15's 16

16's 17

17's 18

18's 19

19's 20

20's 21

21's 22

22's 23

23's 24

24's 25

25's 26

26's 27

27's 28

28's 29

29's 30

30's 31

31's 32

32's 33

33's 34

34's 35

35's 36

36's 37

37's 38

38's 39

39's 40

40's 41

41's 42

42's 43

43's 44

44's 45

45's 46

46's 47

47's 48

48's 49

49's 50

50's 51

51's 52

52's 53

53's 54

54's 55

55's 56

56's 57

57's 58

58's 59

59's 60

60's 61

61's 62

62's 63

63's 64

64's 65

65's 66

66's 67

67's 68

68's 69

69's 70

70's 71

71's 72

72's 73

73's 74

74's 75

75's 76

76's 77

77's 78

78's 79

79's 80

80's 81

81's 82

On one hand your use of printArray() is correct but you are not changing the values in the array between subsequent calls to printArray().

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

{

testRS();

testIR();

testRR();

testIS();

}

Here each test is overwriting the values created by the previous test. You may want to step back at this point and consider creating a "Statistics" class that has: header, array, freq array, total time, min, max, iterations (or something like this). then you can create a Statics object for each one of your tests.

If you want to keep on with your current approach you'll have to execute each test just prior to printing each test results, i.e. test,print,print,test,print,print, etc.

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

Here is how it is

StackOverflowError

StackOverflowError

0's 1

1's 2

2's 3

3's 4

4's 5

5's 6

6's 7

7's 8

8's 9

9's 10

10's 11

11's 12

12's 13

13's 14

14's 15

15's 16

16's 17

17's 18

18's 19

19's 20

20's 21

21's 22

22's 23

Here is what I am expecting

run:

StackOverflowError

StackOverflowError

0's 9081

1's 914

2's 1

5's 2

9's 1

The Recursive Sum

The Longest Time Was9

The Shortest Time Was 0

The Mean Time Was0

0's 9081

1's 914

2's 1

5's 2

9's 1

The Iterative Reverse

The Longest Time Was9

The Shortest Time Was 0

The Mean Time Was0

0's 9081

1's 914

2's 1

5's 2

9's 1

The Recursive Reverse

The Longest Time Was9

The Shortest Time Was 0

The Mean Time Was0

0's 9081

1's 914

2's 1

5's 2

9's 1

The Iterative Sum

The Longest Time Was9

The Shortest Time Was 0

The Mean Time Was0

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

Ryan O'Neill wrote:I expect greater than 7000 0's

They show up like this

0's 1

1's 2

and basically are just an addition of one to the previously stated number if that makes sense

So if the number was 12 it would be 12's 13

And ok will do Thanks for the help thus far

Well, if you're expecting 7000+ entries then it won't fit into an array of size 200.

What is the purpose of the loop?

If you know the record you are after, then you could index to it directly.

It has already been pointed out that because you are using one array to store the results of ALL the tests, and you're not clearing it out between calls, then you get all the frequencies from all the tests in your results array mashed up together.

Doesn't really lend itself to a comparision.

I think conceptually it would be better if your code went something like:

`StackOverflowError`

0's 9950

10's 49

Recursive Sum

The Longest Time Was10

The Shortest Time Was 0

The Mean Time Was0

0's 9950

10's 49

Recursive Sum

The Longest Time Was10

The Shortest Time Was 0

The Mean Time Was0

I think you need to hunt down your overflow problem.

I just tried to do what you did Casey and I got the same output I keep getting. Now I am puzzled

Carey Brown wrote:I just commented out all but one test and called printArray( int[] array ) with rsFreq and this is what I got:

StackOverflowError

0's 9950

10's 49

Recursive Sum

The Longest Time Was10

The Shortest Time Was 0

The Mean Time Was0

I think you need to hunt down your overflow problem.

these are the lines I commented out.

Had to add:

This is what I ran. Note that I also changed currentTimeInMillis to nanoTime which I then divide by 1000 to get micro seconds. At least on my computer milli-seconds was to coarse a measurement.

And here is my output

run:

StackOverflowError

StackOverflowError

0's 9093

1's 905

2's 1

Recursive Sum

The Longest Time Was2

The Shortest Time Was 0

The Mean Time Was0

0's 9093

1's 905

2's 1

4's 1

Iterative Reverse

The Longest Time Was4

The Shortest Time Was 0

The Mean Time Was0

BUILD SUCCESSFUL (total time: 1 second)

You do need to have your tests inside the try block.

Ryan O'Neill wrote:What should the reset method contain?

I think you need to show some effort here. As an example rsTotalTime will need to be set to zero for the results of the next test to have any meaning.

Ryan O'Neill wrote:For my class I am supposed to use Long

I have never used a reset method so I don't know what they should contain

"reset" is just a name I picked out of a hat, call it anything you want.

`0's 9093`

1's 905

2's 1

Recursive Sum

The Longest Time Was2

The Shortest Time Was 0

The Mean Time Was0

1's 905

2's 1

Recursive Sum

The Longest Time Was2

The Shortest Time Was 0

The Mean Time Was0

It is sorta covered in the JavaRanch Style Guide. |