am i correct? please tell me im not sure for my program tnx for the help if any ..

Problem 2: (Fibonacci.java)

Given two numbers f1 and f2, the Fibonacci series defined on f1 and f2 is a sequence of terms s1, s2, s3, s4, s5, … and so on such that s1 = f1, s2 = f2, and sn = sn1 + sn2 for all n > 2 (i.e., the 1st term is equal to f1, the 2nd term is equal to f2, and from the third term onwards, the value of a term is equal to the sum of the two immediately preceding terms; e.g., the value of the 3rd term will be the sum of the 1st and 2nd terms, the value of the 4th term will be the sum of the 2nd and the 3rd terms, the value of the 5th term will be the sum of the 3rd and the 4th terms, and so on).

For example, assuming that f1 = 0 and f2 = 1, the first 10 terms of the Fibonacci series will then be:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34

Write a program that accepts as input values for f1 and f2, as well as a positive integer n. The program then prints out the first n terms of the Fibonacci series defined on f1 and f2, as well as the sum and the average of the said terms.

Code Java:

*// here is my anwser:
import java.lang.*;
import java.util.Scanner;
public class fibunacci{
public static void main(String[]args){
Scanner kbd = new Scanner(System.in);
System.out.print("input number ? ");
int a = kbd.nextInt();
if(a<2){
System.out.println("input");
System.exit(0);
}
int b = 1,c = 0;
System.out.print("the first "+a+" term numbers :");
System.out.print(c+"\t");
System.out.print(b+"\t");
for (int i=3;i<=a;i++){
b = b + c;
c = b - c;
System.out.print(b+"\t");
}
}
}

Re: am i correct? please tell me im not sure for my program tnx for the help if any .

What is your question?

Does your program generate the correct results?

If not, post what it does output and describe what is wrong and show what you'd like it to be.

Please edit your code and wrap it in code tags. See: BB Code List - Java Programming Forums

Or use Go Advanced and use the #icon

Re: am i correct? please tell me im not sure for my program tnx for the help if any .

Please stop multi-posting the same question. I've deleted your duplicate thread.

Follow the advice you've been given, and check out the link in my signature on asking questions the smart way.