CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2014
    Posts
    7

    Post Help with trapezoidal rule java

    Hi folks, need help:

    I tried running the code for trapezoidal rule. It's my project in
    Numerical Methods, here's the code:

    Code:
    static double trapezoidRule (int size, double[] x, double[] y)
       {  double sum = 0.0,
                 increment;
    
          for ( int k = 1; k < size; k++ )
          {//Trapezoid rule:  1/2 h * (f0 + f1)
             increment = 0.5 * (x[k]-x[k-1]) * (y[k]+y[k-1]);
             sum += increment;
          }
          return sum;
       }
    
       public static void main ( String[] args ) throws Exception
       {  String   fileName = args.length > 0 ? args[0] : "InpData.txt";
          Scanner  inp = new Scanner(new File(fileName));
          int      k, size;
          double[] x, y;
          double   integral;
    
          size = inp.nextInt();
          System.out.println ("Number of points:  " + size);
    
          x = new double[size];
          y = new double[size];
    
          for ( k = 0; k < size; k++ )
          {  x[k] = inp.nextDouble();
             y[k] = inp.nextDouble();
          }
          integral = trapezoidRule (size, x, y);
          System.out.printf ("Integral:  %4.4f\n", integral);
          System.out.printf ("Check:  log(%2.2f) = %8.8f\n",
                             x[size-1], Math.log(x[size-1]) );
       }
    }
    It cannot be compiled and I always get FileNotFoundException. I found on Javadocs that this will be thrown when a file with the pathname does not exist. Please help. Thanks!

  2. #2
    Join Date
    Dec 2014
    Posts
    7

    Re: Help with trapezoidal rule java

    Hundreds of views. Thanks for viewing but I really need some answers with this FileNotFoundException issue guys.

  3. #3
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: Help with trapezoidal rule java

    That's because the error cause is that the input file is not found (Java exceptions are pretty descriptive, btw). Check your input file path.
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

  4. #4
    Join Date
    Dec 2014
    Posts
    7

    Re: Help with trapezoidal rule java

    Thanks for the reply xeel! I already checked it several times (maybe hundreds ) and it's on the right (very very right) file path dude but I still have that issue and still could not get results....

  5. #5
    Join Date
    Dec 2014
    Posts
    7

    Re: Help with trapezoidal rule java

    BTW here's the file path....

    C:\Users\GeorgeM\Documents\NetBeansProjects\trapezoidRule\nbproject\textfilespath

    Running crazy about this FileNotFoundException for days now

  6. #6
    Join Date
    Dec 2014
    Posts
    7

    Re: Help with trapezoidal rule java

    Others have advised me that I should just use absolute paths and be done with FileNotFoundException issue.... Any thougths about this guys?

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured