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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

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

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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");
    }
     
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Is this correct.Am I close? Help please
    By eagle09 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 26th, 2011, 07:26 AM
  2. Is My answers correct??
    By Java.Coder() in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 28th, 2010, 06:22 AM
  3. Correct Coupling
    By poulenc in forum Java Theory & Questions
    Replies: 0
    Last Post: December 26th, 2010, 04:28 AM
  4. It's not printing out the correct percentage...
    By JBow94 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 15th, 2010, 04:07 PM