What is a one-dimensional array?
A fixed-size object that stores multiple values of the same type, such as int, double, boolean, or String references.
Study Java One-Dimensional Array Algorithms with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is a one-dimensional array?
A fixed-size object that stores multiple values of the same type, such as int, double, boolean, or String references.
What indices are valid for an array of length n?
For an array of length n, the valid indices are 0 through n - 1. Java arrays use zero-based indexing.
What does int[] scores; do?
Declaration creates a reference variable but not an array object. For example, int[] scores; declares scores without allocating its elements.
What are Java array defaults after new?
new int[5] creates five elements initialized to 0. Java also defaults double to 0.0, boolean to false, and reference types to null.
What is the length of int[] values = {4, 8, 15, 16, 23}?
The initializer list supplies five values, so values.length is 5. An initializer list creates the array and infers its length.
How do you modify one array element?
Use square brackets with an index, such as values[1] = 20, to modify one element. The assignment changes the array itself.
When should you use an indexed for loop?
Use an indexed for loop when the algorithm needs an element's position or must assign new values to the array.
Why cannot a for-each variable modify an array?
The loop variable receives a copy of each element, so assigning to it does not change the array. Use an indexed loop to modify array elements.
What does indexOf({12, 7, 19, 7, 10}, 7) return?
indexOf returns 1, the first index containing 7. It stops at the first match even though 7 appears again at index 3.
What does countEven({12, 7, 19, 4, 10}) return?
countEven returns 3 because 12, 4, and 10 are even. A counting algorithm starts at 0 and increments once per matching element.
What is the average of {12, 7, 19, 4, 10}?
The sum is 52 and the length is 5, so the average is 10.4. Use (double) total / values.length to avoid integer division.
What is the maximum of {-8, -3, -12}?
The maximum is -3. Initializing max with the first element works even when every array value is negative; starting max at 0 would be incorrect here.
A progressive guide to how computing reshapes culture, economic life, public institutions, and individual opportunities, with frameworks for evaluating digital equity, bias, cybersecurity, encryption, and collective participation.
A medium-difficulty assessment of programming fundamentals, algorithmic problem solving, control flow, data structures, testing, debugging, complexity, and decidability. Questions progress from foundational understanding to applied reasoning.
A 14-question quiz on the social, economic, privacy, informational, health, and environmental risks of computing innovations, including strategies for responsible design and oversight.
A practical guide to recognizing cybersecurity threats, protecting accounts and devices, and responding safely when information or systems may be compromised.
A guided introduction to how encryption, authentication, hashing, secure protocols, and key management establish confidentiality, integrity, privacy, and trust while creating practical and legal trade-offs.
A focused review of propositional logic, quantifiers, sets, relations, functions, and foundational proof methods in discrete mathematics for computer science.
A practical guide to evaluating computing innovations by examining their benefits, risks, equity, security, participation, and long-term effects on people and communities.
A medium-difficulty quiz on integrating problem definition, representation, algorithms, complexity analysis, testing, correctness, ethical evaluation, and documentation in a computer science capstone.
A progressive guide to designing, operating, and testing systems that continue useful service despite component faults, overload, data loss, and recovery challenges.
A medium-difficulty quiz on how independently operated networks, protocols, addresses, naming systems, transport services, and routing mechanisms work together to form the Internet.
A progressive guide to how packet-switched networks encapsulate data, move it across links, and manage delay, throughput, queues, and congestion.
A structured guide to designing parallel and distributed systems through decomposition, communication, coordination, state management, scalability, and fault tolerance.