diff options
author | Brian Carlstrom <bdc@google.com> | 2011-08-28 22:41:38 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2011-08-29 09:50:10 -0700 |
commit | 9f30b38d74990286ce27c3a45368f73dbe3638f0 (patch) | |
tree | 81bddd7b70e4b58aadce258cc25bba64de030deb /test/Fibonacci | |
parent | 4417536522fd2a9d8215d8672331984769c9520b (diff) | |
download | art-9f30b38d74990286ce27c3a45368f73dbe3638f0.zip art-9f30b38d74990286ce27c3a45368f73dbe3638f0.tar.gz art-9f30b38d74990286ce27c3a45368f73dbe3638f0.tar.bz2 |
Externalize test code
Change-Id: Iab19397c7a72fb9a3ca63bfd0bc4eaf1a98138ba
Diffstat (limited to 'test/Fibonacci')
-rw-r--r-- | test/Fibonacci/Fibonacci.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/Fibonacci/Fibonacci.java b/test/Fibonacci/Fibonacci.java new file mode 100644 index 0000000..5137205 --- /dev/null +++ b/test/Fibonacci/Fibonacci.java @@ -0,0 +1,30 @@ +// Copyright 2011 Google Inc. All Rights Reserved. + +class Fibonacci { + + static int fibonacci(int n) { + if (n == 0) { + return 0; + } + int x = 1; + int y = 1; + for (int i = 3; i <= n; i++) { + int z = x + y; + x = y; + y = z; + } + return y; + } + + public static void main(String[] args) { + try { + if (args.length == 1) { + int x = Integer.parseInt(args[0]); + int y = fibonacci(x); /* to warm up cache */ + System.out.printf("fibonacci(%d)=%d\n", x, y); + y = fibonacci(x +1); + System.out.printf("fibonacci(%d)=%d\n", x, y); + } + } catch (NumberFormatException ex) {} + } +} |