ErSKS / Java

Java Training
http://khec.edu.np/
MIT License
16 stars 17 forks source link

Develop - Fibonacci Number Checker #35

Closed ErSKS closed 7 years ago

ErSKS commented 7 years ago

Develop a method static boolean isFibonacciNumber(int n)

        System.out.println("1 true:" + isFibonacciNumber(1));
        System.out.println("2 true:" + isFibonacciNumber(2));
        System.out.println("3 true:" + isFibonacciNumber(3));
        System.out.println("4 false:" + isFibonacciNumber(4));
        System.out.println("5 true:" + isFibonacciNumber(5));
        System.out.println("11 false:" + isFibonacciNumber(11));
        System.out.println("21 true:" + isFibonacciNumber(21));
milan604 commented 7 years ago

package finonaccichecker;

/*

screenshot from 2017-08-13 14-44-15

jagdish4249 commented 7 years ago

package fibcheck;

import java.util.Scanner;

/*

karmi214 commented 7 years ago

/*

/*

} f

RakenShahi commented 7 years ago

/*

/*

OUTPUT fibonaccicheck

SusanCB commented 7 years ago

/*

/*

} else { while(n>=a){ c= a+b; a=b; b=c; if(n==a){ count++; break; }

} } if (count>0){ return true; } else { return false; }

} }

fib2

ghost commented 7 years ago

package fibono;

/*

capture

}

}

Sudan15423 commented 7 years ago

/*

/*

} task

kajalmaharjan commented 7 years ago

/*

/*

} 123

rabina12 commented 7 years ago

public static void main(String[] args) { // TODO code application logic here System.out.println("1 true:" + isFibonacciNumber(1)); System.out.println("2 true:" + isFibonacciNumber(2)); System.out.println("3 true:" + isFibonacciNumber(3)); System.out.println("4 false:" + isFibonacciNumber(4)); System.out.println("5 true:" + isFibonacciNumber(5)); System.out.println("11 false:" + isFibonacciNumber(11)); System.out.println("21 true:" + isFibonacciNumber(21)); }

static boolean isFibonacciNumber(int n) {

    int x, y = 1, z = 0;
    while (y < n) {
        x = z;
        z = y;
        y += x;
    }
    return y == n;
}

} fs

kiir33 commented 7 years ago

/*

/*

Output: capturefibonacci

sarumdr commented 7 years ago

/*

/*

}

OUTPUT image

rivab commented 7 years ago

package day10fibonaccichecker;

/*

} day10

ajay987 commented 7 years ago

/*

import java.util.Scanner;

/*

} fibo

sthaanu commented 7 years ago

/*

/*

syslin commented 7 years ago

/*

/*

} 111

sajanbasnet75 commented 7 years ago

/*

/*

luckydivya commented 7 years ago

package fibonacci;

/*

} }

} fibonacci pattern

rituratnam commented 7 years ago

CODE: package fibonacci;

/*

Rajjushrestha commented 7 years ago

public class Fibonacci {

static boolean isFibonacciNumber(int n) {
    int n1 = 0, n2 = 1, n3, f = 0;

    if (n < n1) {
        System.out.println("invalid input");
    } else {
        while (n >= n1) {

            n3 = n1 + n2;

            n1 = n2;
            n2 = n3;
            if (n == n1) {
                f++;
                break;
            }
        }
    }
    if (f > 0) {
        return true;
    } else {
        return false;
    }
}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    int n;

    System.out.println("1 true:" + isFibonacciNumber(1));
    System.out.println("2 true:" + isFibonacciNumber(2));
    System.out.println("3 true:" + isFibonacciNumber(3));
    System.out.println("4 false:" + isFibonacciNumber(4));
    System.out.println("5 true:" + isFibonacciNumber(5));
    System.out.println("11 false:" + isFibonacciNumber(11));
    System.out.println("21 true:" + isFibonacciNumber(21));

}

fb