100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

CS302 EXAM 1 WITH QUESTIONS AND CORRECT ANSWERS

Rating
-
Sold
-
Pages
8
Grade
A+
Uploaded on
21-02-2025
Written in
2024/2025

CS302 EXAM 1 WITH QUESTIONS AND CORRECT ANSWERS....

Institution
CS302
Course
CS302









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
CS302
Course
CS302

Document information

Uploaded on
February 21, 2025
Number of pages
8
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

CS302 EXAM 1 WITH QUESTIONS
AND CORRECT ANSWERS


given: String[] list = {"a", "b", "c"} ; i = 0;
what does list.length vs. list[i].length() return? - ANSWER Array.length is a
property of arrays that returns the number of elements in an array so list.length
returns 3
String.length() is a method of strings that returns the number of characters in a
string, and because 'list' is a string type array, list[i].length() returns the number
of characters at index i in array list so returns 1 ("a" = 1 char)

return type of Math.pow(x, y) - ANSWER double

algorithms - ANSWER a step-by-step set of operations to be performed
- procedure for solving a problem in terms of the actions to be executed and the
order in which those actions are to be executed.
- sequence of steps taken to solve a problem

abstraction - ANSWER a technique for managing complexity

escape sequences - ANSWER special character sequences used within a string
- starts with \
- within " "
\n = newline
\t = tab
\' = '
\" = "
\\ = \

variables - ANSWER name areas of computer memory, declare before use,
declare type of data, initialize

= vs. == - ANSWER = : assignment, assigns values on right to variable on left

, == : conventional definition of equals, or "is"

read in values - ANSWER 1. import java.util.Scanner; // imports scanner
2. Scanner input = new Scanner(System.in); // enables scanner to read input
from System.in
3. int variable = input.nextInt(); // scanner reads next int from System.in
String name = input.nextLine(); // scanner reads next line of input, next string

~same as~
Scanner scnr = new Scanner(System.in);
int variable = scnr.nextInt();
String name = scnr.nextLine();

.nextLine() vs .next() - ANSWER both used to get next string from input,
however -
.next() reads up to the first whitespace(space, newline, tab, or user press
ENTER), reads first non-whitespace thing
-- works when input is one word or when only want first word of input
-- places cursor(scanner) on same line where left off --> if used again, tosses the
whitespace it stopped at and returns next non-whitespace thing
- x = scnr.next()
x.equals("\n") WILL NEVER HAPPEN, scnr.next CANNOT be "\n"
if user input looks like:
1
G
then .next() first returns 1, another .next() starts on the same line and skips any
whitespace(including newline) and returns next non-whitespace thing

.nextLine() reads entire user input on a line up to newline made when user
presses enter or \n when reading from non user input (if user input contains \n
for some reason nextLine() will read \n whereas it would otherwise stop there)
-- moves cursor(scanner) to next line
-- returns the rest of the line, even if its nothing ("")

---BOTH TOSS OUT NEWLINE CHARACTERS

.equals vs. == - ANSWER both return true if the two things being compared
are the same however

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
luzlinkuz Chamberlain University
View profile
Follow You need to be logged in order to follow users or courses
Sold
1427
Member since
4 year
Number of followers
849
Documents
27650
Last sold
1 day ago

3.7

303 reviews

5
131
4
61
3
54
2
17
1
40

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions