Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import acm.program.ConsoleProgram;
  2.  
  3. public class Fibonacci extends ConsoleProgram {
  4.     public void run() {
  5.         int in1 = readInt("Enter a number: ");
  6.         int n1 = 1;
  7.         int n2 = 1;
  8.         int fib = 1;
  9.         while (in1 <= 0) {
  10.             println("Error.");
  11.             break;
  12.         }
  13.         if (in1 == 1) {
  14.             println(in1);
  15.         }
  16.  
  17.         else {
  18.             for (int loop = 1; loop == in1; loop++) {
  19.                 fib = n1 + n2;
  20.                 n1 = n2;
  21.                 n2 = fib;
  22.             }
  23.             println(fib);
  24.         }
  25.  
  26.     }
  27. }
  28.  
  29. 1) Test testNumberElve returned:
  30.     java.lang.AssertionError: expected:<89> but was:<1>
  31.  
  32. 2) Test testNumberZero returned:
  33.     java.lang.AssertionError: Error
  34.  
  35. 3) Test testNumberThirtyone returned:
  36.     java.lang.AssertionError: expected:<1346269> but was:<1>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement