COSC 101

0.0(0)
studied byStudied by 3 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/210

flashcard set

Earn XP

Last updated 3:39 PM on 12/13/22
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

211 Terms

1
New cards
what character(s) is/are used to specify a new line?
%n
2
New cards
public static void main(String\[\] args){

String out = String.format("%-5s", "Hello World"); System.out.print(out);

}

what is printed?
Hello World
3
New cards
int i = 1;
System.out.print(i++);
1
4
New cards
int i = 1;
System.out.print(++i);
2
5
New cards
int i = 1;
System.out.print(i--);
1
6
New cards
int i = 1;
System.out.print(--i);
0
7
New cards
capital types, such as Integer and Double, are called _____ types
reference
8
New cards
int
whole numbers only
9
New cards
boolean
True or False
10
New cards
double
real numbers
11
New cards
String
A sequence of characters
12
New cards
Which of the following data types is a sequence of characters?
int
char
String
chars
Sequence
Character
String
13
New cards
Which of the following formatting specifiers will output a floating-point value with precise to two decimal digits?
%.2f
14
New cards
Which of the following data types are value types?
long
Boolean
Short
bool
double
int
long
double
int
15
New cards
public class abc {
public static void main(String[] args) {
}
}
The source code file for the code above should be named what?
abc.java
16
New cards
class test {
public static void main(String[] args) {
int i = 15;
int j = 20;
System.out.print(i + " " + j);
}
}
What is printed to the screen given the code above?
15 20
17
New cards
Which of the following are value-types?
String
Boolean
double
int
double
int
18
New cards
What is printed to the screen given the following code?

public static void main(String[] args) {
int a = 45 - 4 * 4 / 5 % 4;
System.out.print(a);
}
42
19
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
double a = 2.0;
double b = 7;
double result = Math.pow(a, b);
String out = String.format("%.2f", result);
System.out.print(result);
}
128.0
20
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int a = -2 - -20;
System.out.print(a);
}
18
21
New cards
x -= y
x = x - y
22
New cards
x%= y
x = x%y
23
New cards
x+=y
x=x+y
24
New cards
x/=y
x = x/y
25
New cards
What is printed to the screen given the following code?

public static void main(String[] args) {
int a = 47 + 3 - 2 + 4 % 4;
System.out.print(a);
}
48
26
New cards
Order the following operators based on precedence.

=

&&

%

(int) -- Casting

\+

||
(int)--Casting

%

\+

&&

||

=
27
New cards
\-
difference
28
New cards
\+
sum
29
New cards
%
remainder
30
New cards
=
assignment
31
New cards
/
quotient
32
New cards
*
product
33
New cards
What is printed to the screen given the following code?

public static void main(String[] args) {
double a = 19 / 7;
String out = String.format("%.2f", a);
System.out.print(out);
}
2.00
34
New cards
What is printed to the screen given the following code?

public static void main(String[] args) {
double a = 6.17;
double b = 2.19;
int c = (int)(a + b);
System.out.print(c);
}
8
35
New cards
Since division and multiplication have the same precedence, the evaluation is performed ___ to ___
left right
36
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int i = 2640;
int b = 555;
int c = i++ + --b;
System.out.print(c);
}
3194
37
New cards
What is printed to the screen given the following code?

public static void main(String[] args) {
double a = 5.69;
double b = 2.84;
int c = (int)a + (int)b;
System.out.print(c);
}
7
38
New cards
int a = 1;
switch (a) {
case 0:
System.out.print("A");
case 1:
System.out.print("B");
case 2:
System.out.print("C");
}
What is printed to the screen given the code above?
BC
39
New cards
int a = 5;
String s;
switch (a) {
case 1:
s = "A";
case 2:
s = "B";
case 3:
s = "C";
default:
s = "Z";
}
System.out.print(s);
What is printed to the screen given the code above?
Z
40
New cards
char a = 'A';
System.out.print("A");
switch (a) {
case 'a':
System.out.print("B");
break;
case 'b':
System.out.print("C");
break;
}
What is printed to the screen given the code above?
A
41
New cards
Which of the following data types can be used in a switch statement?
String
char
Double
short
int
Boolean
boolean
double
Integer
float
byte
StringBuilder
Array
String
char
short
int
Integer
byte
42
New cards
A switch statement will end after which of the following? (select all that apply)

exit statement
end of the switch statement (right brace })
out statement
break statement
go to statement
continue statement
end of the switch statement(right brace})
break statement
43
New cards
What Java data type is designed to hold the result of a condition (true/false)?
boolean
44
New cards
public static void main(String[] args) {
int salary = 20000;
if (salary > 10000) {
System.out.print("A");
}
else if (salary > 15000) {
System.out.print("B");
}
else if (salary > 20000) {
System.out.print("C");
}
}
What is printed to the screen given the code above?
A
45
New cards
Which of the following would be used to compare Strings named a and b?
a == b
a.equals(b)
a = b
!(a == b)
a.equals(b)
46
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int a = 10;
int b = 20;
if (!(a == b)) {
System.out.print("True");
}
else {System.out.print("False");
}
}
true
47
New cards
>=
greater than or equal to
48
New cards
!
inversion
49
New cards
<
less than
50
New cards
less than or equal to
51
New cards
==
equal to
52
New cards
!=
not equal to
53
New cards
>
greater than
54
New cards
public static void main(String[] args) {
int salary = 20000;
if (salary > 10000) {
System.out.print("A");
}
if (salary > 15000) {
System.out.print("B");
}
if (salary > 20000) {
System.out.print("C");
}
}
What is printed to the screen given the code above?
AB
55
New cards
public static void main(String[] args) {
int i = 0;
int j = 10;
while (i
2575
56
New cards
A while loop is best used when the number of iterations is...

indefinite
implied
convergent
large
small
divergent
indefinite
57
New cards
public static void main(String[] args) {
int i = 0;
int j = 11;
while (i < 5 && j > 5) {
i += 1;
j -= 1;
}
System.out.print(i + " " + j);
}
What is printed to the screen given the code above?
5 6
58
New cards
public static void main(String[] args) {
int i = 0;
int j = 49;
while (i
2870
59
New cards
public static void main(String[] args) {
int i = 0;
while (i < 13) {
i += 1;
}
System.out.print(i);
}
What is printed to the screen given the code above?
13
60
New cards
public static void main(String[] args) {
int i = -2;
int j = 16;
int k = 30;
while (i < 5 && j > 5 || k >= 1) {
i += 1;
j -= 1;
k /= 6;
}
System.out.print(i + " " + j + " " + k);
}
What is printed to the screen given the code above?
5 9 0
61
New cards
A loop whose condition can never be false is called a/an ____ loop
infinite
62
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int i;
int j = 0;
for (i = 48; i < 472;i++) {
j += 1;
}
System.out.print(j);
}
424
63
New cards
Match the pieces of a for loop with its operation.

for (A; B; C) {
D
}
A- initializer
B- condition
C - step
D - body
64
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int i;
int j = 0;
for (i = 181; i != 32; i--) {
j += 1;
}
System.out.print(j);
}
149
65
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int i;
int j = 0;
for (i = 38; i < 963;i++) {
j += 1;
}
System.out.print(j);
}
925
66
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int i;
int j = 0;
for (i = 169; i != 14; i--) {
j += 1;
}
System.out.print(j);
}
155
67
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int i;
int j = 0;
for (i = 152;i
983
68
New cards
Why do for loops usually start with the value 0?
the world wants 0
Euler says there shalt be 0
computers don't know the difference between 1 or 0
computers start counting from 0
computers start counting from 0
69
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int i;
int j = 0;
for (i = 33; i < 498;i++) {
j += 1;
}
System.out.print(j);
}
465
70
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int i;
int j = 0;
for (i = 153;i
719
71
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int i;
int j = 0;
for (i = 35; i < 587;i++) {
j += 1;
}
System.out.print(j);
}
552
72
New cards
Which of the following data types is required when the specifier %d is used?
int
array
double
ArrayList
String
list
Double
int
73
New cards
public static void main(String[] args) {
int a = 13;
int b = 10;
System.out.print(a % b);
}
What is printed given the code above?
3
74
New cards
Which of the following data types is required when the specifier %f is used?
array
String
list
ArrayList
double
boolean
int
double
75
New cards
Which of the following data types can store real numbers? (select all that apply).
boolean
short
double
Integer
Float
char
float
int
Scanner
String
long
Double
double
Float
float
Double
76
New cards
switch (data) {
case 1:
System.out.print("A");
case 2:
System.out.print("B");
case 3:
System.out.print("C");
break;
case 4:
System.out.print("D");
default:
System.out.print("E");
break;
}
What is printed to the screen given the code above if the variable data equals 2?
BC
77
New cards
Which of the following Boolean operators tests for equality?

>=

<

==
78
New cards
public static void main(String[] args) {
int i = 7;
int j = 2;
int k = 5;
if (i > j) {
System.out.print("A");
}
else if (i > k) {
System.out.print("B");
}
else if (k > j) {
System.out.print("C");
}
else {
System.out.print("D");
}
}
What is printed to the screen given the code above?
A
79
New cards
public static void main(String[] args) {
int i = 2;
do {
System.out.print("A");
} while (i-- > -1);
}
What is printed to the screen given the code above?
AAAA
80
New cards
What does the following code print?

int x = -5;
while (x < 0) {
x++;
System.out.print(x + " ");
}
-4 -3-2-1 0
81
New cards
How many stars are printed when the following code is executed?

for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
System.out.println("*");
}
}
25
82
New cards
What is printed to the screen given the code below?

public static void main(String[] args) {
int i = 1298;
int j = 0;
while (i > 0) {
i -= 1;
j += 1;
}
System.out.print(j);
}
1298
83
New cards
9%4
1
84
New cards
13%6
1
85
New cards
25%7
4
86
New cards
45-4 *4 / 5%4
42
87
New cards
class MyClass {
private int mVar;
public int getVar() {
???
}
}
Write the code to replace ??? above in order to return the private member variable mVar in the code above:
return mVar
88
New cards
Which of the following are part of a method? (select all that apply)
Access protection
Function body
Parameter list
Field list
Name
Return type
access protection
function body
parameter list
field list
name
return type
89
New cards
Variables inside of a class are called
fields
90
New cards
Inputs to a method are provided through which of the following?
parameter list
function body
function name
return type
parameter list
91
New cards
A _____ method does NOT have an implicit this parameter.
static
92
New cards
class MyClass {
private int mValue;
public MyClass(int v) {
mValue = v;
}
public void setValue(int v) {
mValue = v;
}
public int getValue() {
return mValue;
}
}
How would you construct a new instance of the class MyClass above with the initial value of 100? MyClass mc =
newMyClass(100)
93
New cards
The new operator returns a reference of an object in memory.
True or False
true
94
New cards
The access protection ____ means that the method or field is visible to everything outside of the class itself.
public
95
New cards
A method may be overloaded only if its ____ is different.
parameter list
96
New cards
To be able to use non-static fields and methods of a class, we must first have an ____ of that class by using the keyword new.
instance
97
New cards
Every non-static method has an implicit parameter called _____ that refers to the object in memory.
this
98
New cards
class MyClass {
public static void main(String[] args) {
MyClass mc1 = new MyClass();
MyClass mc2 = mc1;mc1.setValue(111);
mc2.setValue(555);
System.out.print(mc1.getValue() + " " + mc2.getValue());
}
public void setValue(int val) {
mValue = val;
}
public int getValue() {
return mValue;
}
private int mValue;
}
What is printed to the screen given the code above?
555 555
99
New cards
A/an ___is a method that has no return type and has the same name as the class itself. It runs when the new operator is executed.
constructor
100
New cards
Every parameter in the parameter list must have which of the following? (select all that apply)
name
data type
return type
method name
name
data type