Results 1 to 4 of 4
Thread: Problem with Java Assignment.
- 12-06-2012, 01:34 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
Problem with Java Assignment.
I'm having a problem with this JDialog Code.
The Fibonacci code is as follows:Java Code:import javax.swing.JOptionPane; public class FibonacciJDialog { public static void main(String[] args) { String num; int n; num = JOptionPane.showInputDialog("Enter n: "); // getting user number input. n = Integer.parseInt(num); Fibonacci box = new Fibonacci(); // Creating new Fibonacci object. JOptionPane.showMessageDialog(null,"That Fibonacci Number is" ); // Display results in dialog box. return sum; System.exit(0); // Terminate } }
Java Code:public class Fibonacci { int Fib (int n) { int in1=1,in2=1; int sum=0;//initial value int index=1; while (index<n) { // sum=the sum of 2 values; // in1 gets in2 // in2 gets sum // increment index } return sum; } }
- 12-06-2012, 02:34 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Problem with Java Assignment.
Please when you ask for some problems then you need to describe the problem to us. Not just post unworking code, tell us which part that give you errors. Because we are not always in front of a Java IDE.
I just try to read your code. There are some errors in there.
1. The main method has a void return. So you cannot return any value from this method.
2. There is no variable named sum. It doesn't valid return statement anyway.
3. You can put statement after a return. It will never reached in execution.Website: Learn Java by Examples
- 12-06-2012, 03:12 AM #3
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
Re: Problem with Java Assignment.
sorry im still new to posting on here. I have made some changes to the code and now I get some different errors.
errors:Java Code:import javax.swing.JOptionPane; public class FibonacciJDialog { public static long main(String[] args) { String num; int n; int sum; num = JOptionPane.showInputDialog("Enter n: "); // getting user number input. n = Integer.parseInt(num); Fibonacci box = new Fibonacci(); // Creating new Fibonacci object. JOptionPane.showMessageDialog(null,"That Fibonacci Number is" ); // Display results in dialog box. return sum; System.exit(0); // Terminate } }
error: variable sum might not have been initialized
return sum;
^
error: unreachable statement
System.exit(0); // Terminate
^\
error: missing return statement
}
^
3 errors
Tool completed with exit code 1
Does this help?
- 12-06-2012, 03:48 AM #4
Re: Problem with Java Assignment.
Stop multiposting. I'm closing two of your threads.
Go through the Forum Rules -- particularly the second and third paragraphs.
db
THREAD CLOSEDWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Java Assignment Problem.
By Southpaw in forum New To JavaReplies: 20Last Post: 12-07-2012, 02:54 AM -
problem with java assignment
By jaire in forum New To JavaReplies: 9Last Post: 03-10-2011, 11:00 AM -
Problem with my assignment - in need of help!
By Chopaan in forum New To JavaReplies: 1Last Post: 01-17-2011, 02:19 AM -
While Loop Problem with Java Assignment Program
By welsh_rocker in forum New To JavaReplies: 9Last Post: 01-12-2011, 01:55 PM -
The Assignment Problem
By bumblyb33 in forum New To JavaReplies: 5Last Post: 03-04-2009, 04:21 AM


1Likes
LinkBack URL
About LinkBacks

Bookmarks