Closed ErSKS closed 7 years ago
package finonaccichecker;
/*
@author m-lan */ public class FinonacciChecker {
/**
static boolean isFibonacciNumber(int n) { return isPerfectSquare(5 n n + 4) || isPerfectSquare(5 n n - 4); } static boolean isPerfectSquare(int n) { int Sq = (int) Math.sqrt(n); return (Sq * Sq == n); } }
package fibcheck;
import java.util.Scanner;
/*
@author Jagdish Duwal */ public class FibCheck {
/**
static boolean isFibonacciNumber(int x ){
int a = 0, b = 1,c,pos=0;
if(x<a) { System.out.println("invalid input");
}else{
while(x>=a){
c= a+b;
a=b;
b=c;
if(x==a){
pos++;
break;
}
}
} if(pos > 0 ) return true; else return false;
}
public static void main(String[] args) { int x;
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));
} }
/*
/*
@author Anish */ public class FibonaciiNumberChecker {
static boolean isFibonacciNumber(int n) { int f1 = 0, f2 = 1; boolean f = false; while (n >= f1) { if (n == f1) { f = true; break; } f2 = f1 + f2; f1 = f2 - f1; } return f; }
/**
}
/*
/*
@author DELL */ public class FibonacciCheck {
static boolean iPS(int x) { int s = (int) Math.sqrt(x); return (s * s == x); }
static boolean isFibonacciNumber(int n) { return iPS(5 n n + 4) || iPS(5 n n - 4); }
public static void main(String[] args) { 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)); } }
OUTPUT
/*
/*
@author nissus */ public class Task102 {
/**
@param args the command line arguments */ public static void main(String[] args) {
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 a=0,b=1,c=0,count=0;
if(n<a) {
System.out.println("invalid input");
} else { while(n>=a){ c= a+b; a=b; b=c; if(n==a){ count++; break; }
} } if (count>0){ return true; } else { return false; }
} }
package fibono;
/*
@author Samikshya */ public class FinoChecker {
static boolean isFibonacciNumber(int n) { int n1 = 0, n2 = 1; boolean f = false; while (n >= n1) { if (n == n1) { f = true; break; } n2 = n1 + n2; n1 = n2 - n1; } return f; } } public class FiboNo {
/**
}
}
/*
/*
@author Dragon15423 */ public class Tasks {
/**
@param args the command line arguments */ 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;
}
}
/*
/*
@author kajal */ public class FabonacciiSeries {
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) { // TODO code application logic here 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));
}
}
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;
}
}
/*
/*
@author Kiran */ public class FibonacciCheck {
/**
}
static boolean fibFunc(int n){
int a=0, b=1, c;
while(a<=n) {
if(a==n)
return true;
c=a+b;
a=b;
b=c;
}
return false;
}
}
Output:
/*
/*
@author sarumdr */ public class Fibocheck {
/**
@param args the command line arguments */ static boolean isFibonacciNumber(int n) { int a = 0, b = 1, c, pos = 0; if (n < a) { System.out.println("invalid input");
} else { while (n >= a) { c = a + b; a = b; b = c;
if (n == a) {
pos++;
break;
}
}
} if (pos > 0) { return true; } else { return false; } }
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));
}
}
OUTPUT
package day10fibonaccichecker;
/*
@author DELL */ public class Day10fibonacciChecker {
/**
@param args the command line arguments */ static boolean isFibonacciNumber(int n) { int n1 = 0, n2 = 1, n3, f = 0; if (n < n1) { System.out.println("Fibonacci of negative number isnot possible"); } else { while (n >= n1) {
n3 = n1 + n2;
n1 = n2;
n2 = n3;
if (n == n1) {
f++;
break;
}
}
} if (f > 0) { return true; } else { return false; } }
public static void main(String[] args) { // TODO code application logic here 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));
}
}
/*
import java.util.Scanner;
/*
@author Dell */ public class Checker35 {
static boolean isfibonnaccinumber(int n) { int f0 = 0, f1 = 1; while (f0 <= n) { if (f0 == n) { return true; } f1 = f1 + f0; f0 = f1 - f0;
}
return false;
}
/**
}
/*
/*
@author admin */ public class FibonaciiCheck {
public static boolean isFibonacciNumber(int n) { int fib1 = 0; int fib2 = 1; do { int Fib1 = fib1; fib1 = fib2; fib2 = Fib1 + fib2; } while (fib2 < n);
if (fib2 == n) {
return true;
} else {
return false;
}
}
public static void main(String[] args) { 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));
} }
/*
/*
@author dell */ public class FibinocSeries {
public static void main(String[] args) { 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 a = 0, b = 1, c, count = 0;
while (n >= a) {
c = a + b;
a = b;
b = c;
if (n == a) {
count++;
break;
}
}
if (count > 0) {
return true;
} else {
return false;
}
}
}
/*
/*
@author LORDsajan */ public class JavaApplication73 {
static boolean isFibonacaii(int x) { int a = 0, b = 1, c, d = 0; while (x >= a) { if (x < 0) { System.out.println("Invalid input"); break; } else { c = a + b; a = b; b = c; if (x == a) { return true; } } } return false; }
public static void main(String[] args) { System.out.println("1 true:" + isFibonacaii(1)); System.out.println("2 true:" + isFibonacaii(2)); System.out.println("3 true:" + isFibonacaii(3)); System.out.println("4 false:" + isFibonacaii(4)); System.out.println("5 true:" + isFibonacaii(5)); System.out.println("8 true:" + isFibonacaii(8)); System.out.println("11 false:" + isFibonacaii(11)); System.out.println("21 true:" + isFibonacaii(21));
} }
package fibonacci;
/*
@author PC */ public class Fibonacci {
/**
static boolean isFibonacciNumber(int n) {
int x, y = 1, z = 0;
while (y < n) {
x = z;
z = y;
y += x;
}
return y == n;
}
} }
}
CODE: package fibonacci;
/*
@author User */ public class Fibonacci {
/**
int x, y = 1, z = 0; while (y < n) { x = z; z = y; y += x; } return y == n; } } Output
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));
}
Develop a method static boolean isFibonacciNumber(int n)