Results 1 to 6 of 6
Thread: Plot Program
- 02-07-2010, 03:45 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 3
- Rep Power
- 0
Plot Program
Hi guys. I'm new to java and signed up for a college java class and was assigned to create a plot program that places an * of a function at a point at execution. I keep getting an ArrayIndexOutOfBoundsException when i try to compile the program. here is the code i have so far. If anyone can help me debug it would be greatly appreciated. Btw I'm writing the code in Eclipse if that helps?
Java Code:public class SmithermanProgram { public static void main(String[] args) { double a= Double.parseDouble(args[0]); double b= Double.parseDouble(args[1]); int n= Integer.parseInt(args[2]); int dx= (int)(b-a)/ n; int i; double x = 0, min = 0, max = 0, y, sf; for (i = 0;i <= n;);{ x = a + i * dx; y = x; if (y > max) max = y; i++; if (y < min) min = y; i++; } sf = 160/(max - min); { x = a + i* dx; y = x; double nSpaces = (y - min) * sf; int j = 0; if (j <= nSpaces) System.out.print(" "); else System.out.println("*"); i++; } System.out.println("a= " + a); System.out.println("b= " + b); System.out.println("n= " + n); System.out.println("dx= " + dx); System.out.println("min= " + min); System.out.println("max= " + max); System.out.println("sf= " + sf);Last edited by Fubarable; 02-07-2010 at 03:53 PM. Reason: code tags added
-
Hello and welcome to the forum. Your program is incomplete -- it's missing its bottom half. Also, which line causes the exception? Also, please use code tags when posting code (see my signature below).
Much luck!
- 02-07-2010, 04:00 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 3
- Rep Power
- 0
very sorry bout the code thing. It says the ArrayOutOfBoundsException is on the line of args[0]. And what do you mean the program is incomplete?
-
Also, this for loop is incorrect:
For one, that semicolon at first line just before the opening brace: ; { is going short circuit the loop. It means that no statement will occur within the loop body. Also, you'll want to increment "i" within that first line of the for loop. So don't do this:Java Code:for (i = 0;i <= n;);{ x = a + i * dx; y = x; //... i++
but instead something more like this:Java Code:int i; for (i = 0; i <= n;);{ x = a + i * dx; y = x; if (y > max) max = y; i++; if (y < min) min = y; i++; }
Java Code://int i; for (int i = 0; i <= n; i++){ x = a + i * dx; y = x; if (y > max) { max = y; } //i++; if (y < min) { // always enclose if's else's for loops, while loops in braces min = y; } //i++; }
-
Then you're not calling your code with command line args. If you're not running the code on the command line but in eclipse, you'll have to tell eclipse to do this for you via it's Run - Run Configurations - Arguments menu item.
By incomplete, I see that your main method has no closing brace nor does the class. The class shows its beginning but not its ending.
You may want to start over on this one.
- 02-07-2010, 04:07 PM #6
Member
- Join Date
- Feb 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
ECG plot in a textfile
By samson in forum Java 2DReplies: 13Last Post: 01-28-2012, 04:02 PM -
using thermometer plot in jfree
By nitish_coder in forum New To JavaReplies: 1Last Post: 10-07-2009, 06:31 PM -
Plot-applet
By zkab in forum Java AppletsReplies: 4Last Post: 10-03-2009, 03:03 PM -
How to plot a dot graph
By Manfizy in forum Java 2DReplies: 3Last Post: 01-28-2009, 02:57 PM -
Need Help for Dot Plot Graph
By BHCluster in forum Java 2DReplies: 5Last Post: 04-15-2008, 02:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks