Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Problem with Java Assignment.

  1. #1
    Southpaw is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Problem with Java Assignment.

    I'm having a problem with this JDialog Code.
    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
    
        }
    }
    The Fibonacci code is as follows:
    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;
    		}
    	}

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default 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.

  3. #3
    Southpaw is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default 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.
    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
    
        }
    }
    errors:
    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?

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

    Default 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 CLOSED
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Java Assignment Problem.
    By Southpaw in forum New To Java
    Replies: 20
    Last Post: 12-07-2012, 03:54 AM
  2. problem with java assignment
    By jaire in forum New To Java
    Replies: 9
    Last Post: 03-10-2011, 12:00 PM
  3. Problem with my assignment - in need of help!
    By Chopaan in forum New To Java
    Replies: 1
    Last Post: 01-17-2011, 03:19 AM
  4. While Loop Problem with Java Assignment Program
    By welsh_rocker in forum New To Java
    Replies: 9
    Last Post: 01-12-2011, 02:55 PM
  5. The Assignment Problem
    By bumblyb33 in forum New To Java
    Replies: 5
    Last Post: 03-04-2009, 05:21 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
  •