Beruflich Dokumente
Kultur Dokumente
Printf
Math.sqrt
All return doubles
Random
Need to import java.util.Random
Generates a random integer or double
For nextInt(), the # in () is exclusive
o Random rand = new Random();
o Int a = rand.nextInt(4) + 4; [range is 4,7]
Read and Write Files
You have to know how to read and write from file
o PrinterWriter toFile = newPrintWriter();
o Scanner fromFile = new Scanner(new
FileReader(filename.txt))
o toFIle.println()
o System.out.println(fromFile.nextLine())
o toFile.close()
you need this on main method
o public static void main (String[] args) throws IOException
import java.io.*;
Methods
if you are calling the method from main, the method has to be
static
a method has to have a return type
o the return types are void, Boolean, int, String, char, double
float
public static double myMethod(int a, double b)
double- return type
myMethod method name
(int a, double b)- parameters
Recursion
when a method calls itself
have to have base cases in order to stop the method from calling
itself
use return; to exit
REVIEW PRACTICE NOTES
if int is divided by int it will come out with if int division even it is
being put into a double
o n1 = 17;
o d1 = n1/4
o d1 prints as 4.0
string.length starts counting the first character as 1 and includes
spaces
import java.util.Scanner
Scanner keyboard = new Scanner (System.in);
Scanner inputFile = new Scanner (new FileReader(input.txt));
PrintWriter outputFile = new PrintWriter (new
FileWriter(output.txt));
When declaring string as variable capitalize s
Cant start variable name with number