Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

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

1. ## 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.

```*// 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");
}

}
}```  Reply With Quote

3. ## Re: am i correct? please tell me im not sure for my program tnx for the help if any .  Reply With Quote
4. ## Re: am i correct? please tell me im not sure for my program tnx for the help if any .  Reply With Quote