Results 1 to 14 of 14
  1. #1
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default In need of dire help

    SO, I am required to take JAVA in my school as a course (only half year tho). And I am really stumped, I dont get java or Oracle (last year)... I have to make a code that tells me fibonacci sequence. Like if I go what is the 7th term the code will come out with 13.
    But honestly I have no idea so here is my start/ best attempt

    PHP Code:
    import java.util.scanner;
    {
    public class FibonacciFinder
    public static void main(String[]args)
    {
    scanner input = new scanner(system)
    int fib = 1;
    int start= 0;
    int end= 0;
    int sequence=1;
       While(count<= sequence)
       start=end;
       end=fib;
       fib=start+end;
       count=count+1;
    system.out.println("The" +emd +"term in the sequence is" + fib);
    }
    }
    I honestly have no idea andI am pretty sure there is something between my while statement and my declaring statements
    if anyone could not beat me up to bad with how bad it is it would be greatly appreciated!

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default Re: In need of dire help

    Do you get a compile error? An error when the program is run? The wrong output?

  3. #3
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Re: In need of dire help

    Have you been given any tutorials or lab notes from your school on java, or have they left it up to you to work it out for yourself?
    There are a number of things i can see before you attempt to run.
    Your import statement and creation of you Scanner are wrong, take a look here > Scanner (Java 2 Platform SE 5.0) I have also added a hint in my message for you.
    Also take a look at the curly braces for public class FibonacciFinder.
    In your program you are also using count, but you don't define what count is. There is also spelling mistakes and a number of capital letters included where they shouldn't be and not included where they should.
    I advise you look over any lab notes you were given, see your teacher and ask for some further help/advice and i would also definitely review the basics of java programming first.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,419
    Rep Power
    20

    Default Re: In need of dire help

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,419
    Rep Power
    20

    Default Re: In need of dire help

    Quote Originally Posted by wdh321 View Post
    Please don't post links to old end-of-life versions of the Java API. Here are the two currently supported versions:
    Java Platform SE 6
    Java Platform SE 7

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default Re: In need of dire help

    PHP Code:
    import java.util.Scanner;
    public class FibonachiFinder
    {
    	public static void main(String[]args)
    	{
    		double fib;
    		double start = 1;
    		double end = 1;
    		double count;
    
    		System.out.println("Enter the Fibonacci number you want to display");
    		Scanner input = new Scanner(System.in);
    		count = input.nextDouble();
    
    
    		while(count>= 3)
    			{
    			fib = start + end;
    			start = end;
    			end = fib;
    
    
    			System.out.println(fib);
    		}
    	}
    }
    here is my updated code. that I came up with. I know when I put in a count --; I get it to work, I put this above fib = start + end

  7. #7
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default Re: In need of dire help

    So what happens? What do you expect to happen?

  8. #8
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default Re: In need of dire help

    i get 1.0

    What i expect to happen is the user puts in 7 and my out put becomes 13... that is it
    and when I put in
    PHP Code:
    count --;
    above fib = start + end;
    it works but counts all the fibonacci numbers up to it, which as of now i do not want

  9. #9
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default Re: In need of dire help

    Okay then. If it works when you put that line in there, let's look at it a bit closer. This is what happens in the while-loop:
    Java Code:
    while(count>= 3)
    {
      count --;
      fib = start + end;
      start = end;
      end = fib;
      System.out.println(fib);
    }
    See anything there that might cause it?

  10. #10
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default Re: In need of dire help

    Quote Originally Posted by Toll View Post
    Okay then. If it works when you put that line in there, let's look at it a bit closer. This is what happens in the while-loop:
    Java Code:
    while(count>= 3)
    {
      count --;
      fib = start + end;
      start = end;
      end = fib;
      System.out.println(fib);
    }
    See anything there that might cause it?
    yes exactly... and then it writes --> 1,1,2,3,5,8,13 and stops... I just want the output to be 13....

  11. #11
    SJF
    SJF is offline Senior Member
    Join Date
    Oct 2012
    Posts
    108
    Rep Power
    0

    Default Re: In need of dire help

    look at where your println statement is... inside a loop!

  12. #12
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Re: In need of dire help

    Quote Originally Posted by NOIDEABOUTJAVA View Post
    yes exactly... and then it writes --> 1,1,2,3,5,8,13 and stops... I just want the output to be 13....
    Look at which line in your loop may be causing your program to print each value.
    Then simply remove this from the loop, then you can place a line which displays the final value you calculated.

  13. #13
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default Re: In need of dire help

    Quote Originally Posted by SJF View Post
    look at where your println statement is... inside a loop!
    i thought it needs to be in the loop because i need it to loop until it hits the 7th fibonacci number

  14. #14
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default Re: In need of dire help

    Anything in the loop is executed at every loop. So you will print every time you calculate a new Fibonacci-number. If you just want to print the last one, it needs to be just after the loop ends.

Similar Threads

  1. New Java Student in dire need of help
    By Leonspade in forum New To Java
    Replies: 11
    Last Post: 11-22-2010, 09:28 PM
  2. I need DIRE DIRE HELP
    By Meta in forum New To Java
    Replies: 5
    Last Post: 03-11-2010, 08:39 AM
  3. I Am In Dire Need Of Help
    By diptarka.ray in forum Advanced Java
    Replies: 2
    Last Post: 10-20-2008, 09:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •