Useful knowledge for worksheet 1.

- Inside a method statements are separated by semicolons (;).
- In calculations each variable must have a type e.g. double (see the Java tutorial).

Q: How do I display a line of text?

A: To display "A line of text", you need the line

System.out.println("A line of text");

If you wish to print out text along with a number, you would use

System.out.println("My favorite number is" + 42);

 

Q: How do I access the numerical constants Pi and E? How do I find SIN(something in radians)

A: The numerical constant Pi is accessed by

java.lang.Math.PI

The numerical constant E is accessed by

java.lang.Math.E

To take the sin of the variable ``something'', which is in units of radians, use

java.lang.Math.sin(something)

 

Q: How do I take a power or a root?

A: Taking powers or roots can be done with the same method (function). In general, if you want to calculate a^b, you use

java.lang.Math.pow(double a, double b);