Help need on math java program

Hi I am trying to write a java program that lets me evaluate the value of x over the range x=0 to100, for the function y=a*(x*8))+b*((x*8)^-0.5))+c and then print the values of y into a file. However the attempt I made below does not work can someone help me out and show me where I am going wrong and what to do to make the code work.

Code Java:

public class javatest {
public static void main(String[] args) {
// Stream to write file
FileOutputStream fout;
try
{
// Open an output stream
fout = new FileOutputStream ("output.txt");
double a = 5;
double b = 10;
double c = 15;
double y;
double x;
y=(a*(x*8))((b)*Math.pow((x*8)),-0.5)+c;
// for x returns y for 100 channels.
for (x=0; x < 100; x+) {
System.out.println(
"The value of y is " y;
// Print a line of text
new PrintStream(fout).println (" The value of y is" y;
// Close our output stream
fout.close();
}
}
}

Re: Help need on math java program

See post on other thread.

Re: Help need on math java program

If you're serious about this, try to compile and at least try to fix the errors yourself, otherwise get back here and post the errors too.

Hint : I can see one error there which should yell a LOT when you try to compile that.

Re: Help need on math java program

You've left a lot of mistakes as far as syntax is concerned; fix those or at least compile and see :S.

For the logic of your program, i guess you'll want to put the equation in that for loop.

Re: Help need on math java program

To give a indication of what the others mean, I saw atleast 7 mistakes in syntax that should give huge errors.

Re: Help need on math java program

very obvious syntax errors

Re: Help need on math java program

My guess is this is your first program, so I'll help out as much as I can.

Here are some problems you may be facing:

1) Have you imported FileOutputStream and PrintStream?

import java.io.FileOutputStream;

import java.io.PrintStream;

2) You attempted to create a TRY block, but you failed to take account of an error occuring. After the block, you need to include either a CATCH or FINALLY block. I will include an example of a CATCH block since that is the simplest and most useful for your situation.

CATCH Block: "catch(Exception e){System.out.println(e);}"

3) You did not initialize the variable "x". Give it a value before you attempt to use it in the formula.

4) You incorrectly attempted to use Math.POW(double d1,double d2).

Your wrote: "((b)*Math.pow((x*8)),-0.5)"

While it should be: "((b)*Math.pow((x*8),-0.5))"

Always make sure your brackets are in the correctly place. I also believe you have forgotten a plus ( + ) if the formula in your description is correct.

5) You incorrectly attempted to print out your results.

Your wrote: "System.out.println("The value of y is " y;"

While it should be: "System.out.println("The value of y is "+y);"

Your wrote: "new PrintStream(fout).println (" The value of y is" y;"

While it should be: "new PrintStream(fout).println (" The value of y is "+y);

Keep in mind to include a bracket to close the println() method and keep in mind that to add a number to a string, you have to close the string, include a plus ( + ) and then include the number you want to add. It also doesnt hurt to include a space after "is" so there will be a space between "is" and the number during the output.

6) Lastly, you have forgotten an ending bracket ( } ). Put one at the end or where you are wanting to end a code block.