Write a program in Java, ( 1 ) fibonacci - Takes as argument a single non -
Fantastic news! We've Found the answer you've been seeking!
Question:
Write a program in Java,
"fibonacci" Takes as argument a single nonzero, positive integer and prints the fibonacci series up to the highest fibonacci number that is smaller or equal to the input
argument. The output should be in ascending order with a single space character separating each integer.
Eg: If is the input argument, the output would be is not a fibonacci number so we print up to the highest fibonacci number that is less than or equal
to ; in this case that is
Eg: If is the input argument, the output would be is a fibonacci number, so we print all the fibonacci numbers up to and including
Eg: If is the input argument, the output would be
If the input argument is anything other than a positive, nonzero integer, you must print the string "error".
Eg: If is the input argument, output must be "error".
Eg: If "helloworld" is the input argument, output must be "error"
Eg: If is the input argument, the output must be "error".
"overlap" Takes as argument a list of ranges and determines whether any two ranges overlap. If there is any overlap, it prints "true", otherwise it prints "false".
A range is given in the form ab where a and b are both integers and where a b Note that a and b can be negative, zero or positive. A list of ranges is a sequence of
ranges separated by a single space character : ab xy jk Two ranges overlap if they partially, or fully cover the same set of integers. For example: and
overlap because they both include and Similarly, and also overlap because they both include and On the other hand, and do not
overlap because they do not share any integers.
If you encounter a malformed range, you must print "error". A malformed range, ab is one where either a or b are not integers or where a b
For example, the following ranges are all malformed "five,$$ "hello,world".
The "overlap" function is guaranteed to be given a list of at least two intervals, therefore you need not worry about an empty list or a single
range as arguments.
Eg: Given as input, the function would print "true" because and overlap.
Eg: Given as input, the function would print "false" because no ranges overlap.
Eg: Given dd as input, the function would print "error" because dd is a malformed range.
"stats" Takes no arguments and prints the number of calls to "fibonacci" and "overlap" in that order as two integers, on a single line, separated by a single space
character
Eg: If "fibonacci" is called three times, and "overlap" is called twice, the output should be
The input to your program will be given on stdin and will consist of one function call per line. Each line starts with a string fibonacci
"overlap" or "stats" indicating which function is being called. Following the function name, there will be a single space character
after which the input to the function if any is presented. If "stats" is called, it will always be the last function call.
Sample input:
fibonacci
overlap
fibonacci
fibonacci
overlap
stats
Sample output:
false
error
true
Related Book For
Posted Date: