CSC 1351 : Notes Pre Midterm

25 views27 pages
15 Mar 2019
School
Course
Professor

Document Summary

Public boolean haspositive(int[]nums: constructor due to it"s capitalized name, int[]nums is array with a name. Fundamental theorem of programming: any computation can be expressed using only, assignment statement, conditional statements, loop statement, applies to java and all other languages. Control variable in a for loop must not be updated in the loop body. While statements are more general than for statements (use for loop if it works) Permutation: integers in a certain order with no repetition: counter example: repetition, n! permutations. More importantly, if the loop needs to be separated to be efficient, do it. Computing a random integer 5-15 given random rand = new random(0: 5 + rand. nextint(11); Show random numbers for [5,4,3,2,1,0] for efficient method (from laboratory: first m = 0, second m = 1. [0,1] or [1,0] i = numitems 1, numitems 2, 1: initialization: permutation [0,1, m = rand. nextint(i) = 0, permutation = [1,0] final result only one permutation, but rand. nextint(i+1), m =1 or 0.