Results 1 to 14 of 14
Thread: In need of dire help
- 10-24-2012, 05:38 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
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
I honestly have no idea andI am pretty sure there is something between my while statement and my declaring statementsPHP 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); } }
if anyone could not beat me up to bad with how bad it is it would be greatly appreciated!
- 10-24-2012, 11:14 AM #2
Re: In need of dire help
Do you get a compile error? An error when the program is run? The wrong output?
- 10-24-2012, 03:09 PM #3
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
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.
- 10-24-2012, 05:31 PM #4
Re: In need of dire help
Please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-24-2012, 05:34 PM #5
Re: In need of dire help
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
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-24-2012, 07:18 PM #6
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: In need of dire help
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 + endPHP 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); } } }
- 10-24-2012, 07:31 PM #7
Re: In need of dire help
So what happens? What do you expect to happen?
- 10-24-2012, 11:08 PM #8
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
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 inabove fib = start + end;PHP Code:count --;
it works but counts all the fibonacci numbers up to it, which as of now i do not want
- 10-24-2012, 11:12 PM #9
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:
See anything there that might cause it?Java Code:while(count>= 3) { count --; fib = start + end; start = end; end = fib; System.out.println(fib); }
- 10-25-2012, 12:14 AM #10
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
- 10-25-2012, 12:22 AM #11
Senior Member
- Join Date
- Oct 2012
- Posts
- 108
- Rep Power
- 0
Re: In need of dire help
look at where your println statement is... inside a loop!
- 10-25-2012, 12:29 AM #12
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
- 10-25-2012, 12:42 PM #13
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
- 10-25-2012, 12:51 PM #14
Similar Threads
-
New Java Student in dire need of help
By Leonspade in forum New To JavaReplies: 11Last Post: 11-22-2010, 09:28 PM -
I need DIRE DIRE HELP
By Meta in forum New To JavaReplies: 5Last Post: 03-11-2010, 08:39 AM -
I Am In Dire Need Of Help
By diptarka.ray in forum Advanced JavaReplies: 2Last Post: 10-20-2008, 09:39 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks