APCS A EVERYTHING YOU NEED TO KNOW

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

DeMorgan's Law: !(a <= b || b > c) becomes?

(!a > !b && !b <= !c)

Binary Search

- already sorted - more efficient than sequential sort - Splits in half mid = (low + high)/2 if (answer is = to mid --> found answer else if (answer is < mid) -->key is in left half or array searches for key from low to mid -1 else ---> key is in right half of the array searches for key from (mid + 1) to highest - Fasted = key is found in the middle - Slowest/worst case = key is found at the end of a sub list or not even in the list number of comparisons in worst case ---> round n to the next power of 2 and take the exponent ex: n = 9 round 9 up to 16 = 2^4 so four comparisons needed

String one = "ABC123"; String two = "C"; String three = "3"; System.out.println(one.indexOf(two)); System.out.println(one.indexOf(three)); System.out.println(two.indexOf(one)); Output?

2 5 -1 use your common sense why would two = the number two? its the fricking variable name so its one.indexOf(C) not two

int types use ____ bits largest integer is ________

32, 2^31 -1

int one = 1; int two = 2; String zee = "Z"; System.out.println(one + two + zee); Output?

3Z/ one and two are int variables so the + adds them up inside the print thing and doesnt concatentate them

String str = "AP"; str += "CS " + 1 + 2; System.out.println(str); Output?

APCS 1 2 1 and 2 are treated as strings because theres the "CS" in front of it so they aint added if it was stri += 1 + 2 then it would add them up

x/0

Arithmitic Exception

Array[-1]

ArrayIndexOutOfBounds

How 2 declare an arrayList?

ArrayList <Type> name = ArrayList<Type>();

\\ in print statement

Backslash (\)

mergesort

Break the array into 2 halves Merge sort the left half merge sort the right half merge the two sub arrays into sorted array breaks it into sublist with length 1 adjacent pairs of lists are merged -Disadvantage : needs a temporary array as large as og array - Worst and Best Case have similar run times.

Subclasses

Cant directly access private variables if inherited from a super class must be public

Format for creating a new object and calling the constructor

Class name = new Class("parameter", "here")

.compareTo() String p = ("poopy"); String b = ("bum"); p.compareTo(b)

Compares string in alphabetical order returns <0 if this is less than other returns zero if this is equal to other returns >0 if this is greater than other

Double (double value)

Constructs a new Double object that represents the specified double value

\"

Double-quote (")

Overflow Error

Error from attempting to represent a number that is too large. even if i just define a variable that is outside the range it'll error

for(int i = 0; i<mat.size(); i++) { for(int k = 0; k<mat[0].size(); i++) { mat[i][k].set(i); } } What is the output?

Error, because the code uses ArrayList methods for 2D Arrays, instead of array methods. IT USES SIZE AND NOT LENGTH

String s1 = "ABCDEFGHI"; String s2 = s1.substring(6, 7); String s3 = new String("abcdefghi"); String s4 = s3.substring(4, 5); String s5 = s3.substring(2, 3); System.out.print(s2 + s4 + s5);

Gec DUDE DONT FORGET TO START COUNTING AT ZERO

Output? double num = 9 / 4; System.out.print(num); a) 2.25 b) 2.0 c) 2

INTEGER DIVISION even though its in double, because the two numbers are default int types, it does integer division so its gonna be/ b

Int has a max and min value, instead of typing out the huge number (214783647) what can we use instead?

Integer.MAX_VALUE; Integer.MIN_VALUE;

Identifier

Just the name for a variable, parameter, constant, user defined method, or user defined class.

does ^ 2 do anything

NO! you have to do Math.pow silly!!!

\n

New line

Private

Not useable outside of the class

indexOf() String h = ("poopybum"); System.out.println(h.indexOf("u")); Output?

Returns the position of the first found occurrence of a specified value in a string starts at 0 Output: 6

double doubleValue()

Returns the value of this Double as a double

int intValue()

Returns the value of this Integer as an int.

Short circuit evaluation

Short circuit evaluation skips evaluating later operands if the result of the logical operator can already be determined. So it doesnt even go through buddy! LOOK At this example: n=6 if (n! = 100 && n/0) return n else return n + 22 a) Arithmetic Exception will be thrown b) returns n + 22 Answer : b because it doesnt even go to the second part and statement because n! Is false this also happens if True||

implicit parameter

The object on which a method is invoked. For example, in the call x.f(y), the object x is the implicit parameter of the method f.

Public

Useable outside of the class

Consider the following code segment, which is intended to assign to num a random integer value between min and max, inclusive. Assume that min and max are integer variables and that the value of max is greater than the value of min. double rn = Math.random(); int num = /* missing code */;

YOU HAVE TO ADD THE +1 SO IT FRICKIN INCLUDES THE NUMBER!! FOR EXAMPLE IF YOU SAY MATH.RANDOM * 100 IT ONLY WILL PRODUCE 0-99.999 SO YOU GOTTA MULITPLY IT BY 101 SO IT WILL PRODUCE A NUMBER FROM 0 - 100!!! answer : a) (int) (rn * (max - min + 1)) + min

ArrayList.set(i, value)

a method of ArrayList class used to set i position with new value.

Insertion Sort

adds it to the front - array is sorted after n-1 passes after - not efficent because of so many passes - Worst case = reverse order -Best case = already in increasing order

A static method is one called without ________

an object; use the class name with the dot operator

Binary search function

binarySearch(array, value) returns the index of the SORTED array (or < 0 if not found) MUST BE SORTED!!!

int + double

double

roundoff error: happens when: 3.0 == (3.0 (x))/(x)

error that is produced when a computer is used to perform real number calculations because many real numbers can not be represented exactly on a computer. happens anytime operations are used on decimal numbers not true because of round off error

Selection sort

finds the smallest element is exchanged with a[0] ( first element) swapping it sorted after n-1 passes after the kth pass the first k elements are in their final sorted position

static

for METHODS that will not access any objects of a class

String s = "hello" + true + "bye" + false; System.out.println(s);

hello true bye false it prints the booleans because of + operator

int + int

int

List Built in/Primitive Types

int boolean double

Output? double x = 4.5; int y = (int) x * 2; System.out.print(y); a) 8 b) 8.0 c) 9

int y = (int) (4.5) * 2 int y = (4) * 2 int y = 8 DONT FORGET PEMMDAS (modulus is included) so it casts it to an int first and truncates the decimal THEN it multiplies so its gonna be/ a

(int) (math.random() * 100 + 1) (int) (math.random() * 100 ) (math.random() * 100 )

integer from 1-100 ( range becomes 1 - 100 (inclusive) integer from 0-99 (inclusive bc it has 100 diff results) OR 0-100 (exclusive of the number 100) number from 0-100

matrix[y].length

number of columns in a specific row at index y

matrix.length

number of rows

String h = ("poopybum"); h.substring(2,6); h.substring(2); Output?

oopyb (not inclusive so it goes up until 6 not on 6) opybum

Final Variable ( class variable method) final variables create a ______ final classes prevent _______ final methods prevent _______ final variable can be declared ____

quantity whose value will not change final variables create a constant final classes prevent inheritance final methods prevent overriding final variable can be declared without initializing it immediately.

String h = ("poopybum"); h.lenght()

returns length of string 8

Power of method parameters

static double pow(double BASE, double EXPONENT)

explicit parameter

the parameters object.blah("bunny", 293);


Ensembles d'études connexes

Fund A Lecture 9: RNA & Protein Synthesis

View Set

Chapter 7 Legal Dimensions of Nursing Practice

View Set

1.6 Real Estate The Business of Value

View Set

Chapter 5-Disability Income and Related Insurance ExamFx quizzes

View Set