CS302 EXAM 1 QUESTIONS WITH CORRECT ANSWERS 100% VERIFIED| GUARANTEED SUCCESS
given: String[] list = {"a", "b", "c"} ; i = 0;
what does list.length vs. list[i].length() return? 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) double
algorithms 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 a technique for managing complexity
escape sequences special character sequences used within a string
- starts with \
- within " "
\n = newline
\t = tab
\' = '
\" = "
\\ = \
, variables name areas of computer memory, declare before use, declare type of data,
initialize
= vs. == = : assignment, assigns values on right to variable on left
== : conventional definition of equals, or "is"
read in values 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() 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
given: String[] list = {"a", "b", "c"} ; i = 0;
what does list.length vs. list[i].length() return? 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) double
algorithms 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 a technique for managing complexity
escape sequences special character sequences used within a string
- starts with \
- within " "
\n = newline
\t = tab
\' = '
\" = "
\\ = \
, variables name areas of computer memory, declare before use, declare type of data,
initialize
= vs. == = : assignment, assigns values on right to variable on left
== : conventional definition of equals, or "is"
read in values 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() 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