Results 1 to 3 of 3
  1. #1
    walia6 is offline Member
    Join Date
    Jul 2015
    Posts
    1
    Rep Power
    0

    Angry One of my first scripts

    Hi, so this is one of my first scripts. Its supposed to be able to print the first 20 fibonicci numbers. It seems that I am doing something wrong!

    Java Code:
    class HelloWorldApp {
      public static void main(String[] args) {
        String currentVal;
        String current;
        double[] myList = new double[20];
        myList[0] = 1.0;
        myList[1] = 1.0;
        for (int i=3; i<21; i++) {
          myList[i-1] = myList[i-2] + myList[i-3];
        }
        for (int i=0; i<20; i++)
          currentVal = String.valueOf(i+1);
          current = String.valueOf(myList[i]);
          System.out.println(currentVal + " fibonicci number is: " + current);
      }
    }
    Error:
    Java Code:
    HelloWorld.java:18: error: cannot find symbol
          current = String.valueOf(myList[i]);
                                          ^
      symbol:   variable i
      location: class HelloWorldApp
    1 error
    Thanks in advance!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: One of my first scripts

    The code you posted has 16 lines but the compiler error is on line 18. If you want to get help, you need to post the code that actually led to that error.

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

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: One of my first scripts

    Your use of { }s is not consistent. You should always use { } to wrap code that is inside of a loop or if statement.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. How do I seperate names in this scripts
    By techboy992 in forum New To Java
    Replies: 4
    Last Post: 02-26-2014, 09:29 AM
  2. Scripts
    By AndrewM16921 in forum Advanced Java
    Replies: 1
    Last Post: 02-07-2013, 06:19 PM
  3. Replies: 1
    Last Post: 02-16-2012, 09:24 AM
  4. Ant: Using Ant target to generate shell / batch scripts
    By ignisfatuus in forum Advanced Java
    Replies: 0
    Last Post: 07-22-2011, 09:21 PM
  5. Run ant scripts using ProcessBuilder
    By prsindagi in forum Advanced Java
    Replies: 6
    Last Post: 02-11-2009, 10:26 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
  •