Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 4th, 2014, 03:52 AM
Registered User
 
Join Date: Dec 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help for trapezoidal rule java program

Hi guys. 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 error. Any thoughts? Please help. Thanks!
 
Old December 5th, 2014, 05:11 AM
Registered User
 
Join Date: Dec 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys just found out that FileNotFoundException is an exception that is thrown when an attempt to access a file that does not exist on disk fails... However I checked the file path many times (manymanymany too many) and it's on the right file path...
 
Old December 6th, 2014, 03:50 AM
Registered User
 
Join Date: Dec 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Btw here's the file path for the text file:

C:\Users\GeorgeM\Documents\NetBeansProjects\trapez oidRule\nbproject\textfilespath

Is this wrong?
Running crazy about this FileNotFoundException for days now....





Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Program indupriyav J2EE 0 May 29th, 2010 04:29 AM
java program help chris1012 Java Basics 3 November 8th, 2007 09:35 AM
java program todeepak_g JSP Basics 0 January 25th, 2006 06:04 AM
java program todeepak_g JSP Basics 0 January 25th, 2006 06:01 AM
My Java program won't compile emilaghayev JSP Basics 0 October 21st, 2003 06:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.