CSE 110 FINAL (JAVA)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

which of the following correctly declares a variable of type int in Java? a. int a = new int(); b. int a; c. int a = 0 d. a = int(3); e. int[] a = 0 f. int [] a = new int [3]; g. none of these

b, c

Which of the following are Java primitive data types? a. String b. float c. Random d. boolean e. char f. int g. Array h. math i. double j. class k. none of these

b, d, e, f, i

suppose you are given the code below. what should the output be? String str1 = "abc"; String str2 = "abc"; if (str1 == str2) { System.out.println("True"); } else{ System.out.println("False"); } a. true b. false c. run time error

b, for strings the .equals() method must be used

suppose you are given the code below. Are there any issues? int i = 1; while (i <= 3) { System.out.println(i); } a. no issues b. infinite loop c. run time error due to integers not being allowed in while loop conditions

b, i was never incremented so 1 will always be printed

given the following declaration: String s1 = "banana"; String s2 = "apple"; evaluate the expression: s2.compareTo(s1)>0 a. true b. false c. none of these

b, if first string is greater in length then second string then it is 1, if the second string is smaller in length then the first one then it is -1, same length is 0

given the following declaration: String s = "Apples and bananas are yummy."; Evaluate the expression: s.indexOf("an") a. -1 b. 0 c. 7 d. 8 e. 9 f. 10 g. 11 h. 12 i. none of these

c

given the following declaration: String s = "Apples and bananas are yummy."; evaluate the expression: s.substring(1,4) a. "A" b. "Ap" c. "p" d. "pp" e. "Apple" f. "Apple and" g. none of these

g

what is the output of the following java program? Class Driver { public static void main(String[] args) { foo(3); bar(5); } static void foo(int a) { bar(a+1); System.out.print(a); } static void bar(int a) { System.out.print(a); } } a. 435 b. 653 c. 453 d. 563 e. 445 f. 365 g. none of these

a

what is the output of the following java program? Class Driver { public static void main(String[] args) { int a = 3; int b = 5; if (a>b || a * 2 > b) System.out.print(a); else System.out.print(b); } } a. 3 b. 5 c. 2 d. 8 e. none of these

a

which of the following would correctly declare and instantiate an array of 4 ints? a. int[] values = new int [4]; b. int[] values = new int [5]; c. int[] values = new int [6]; d. int[4] values = new int []; e. int[5] values = new int []; f. int[6] values = new int []; g. int[4] values = new int [4]; h. int[5] values = new int [5]; i. int[6] values = new int [6]; j. int[] values = int[4]; k. int[] values = int[5]; l. int[] values = int[6]; m. none of the above

a

Which of the following Java literals have the data type int? a. 123 b. 3f c. 3.14 d. -3 e. 'a' f. "3.0" g. '\n' h. 3.14f i. true j. false k. "true" l. 3.0

a, d

which of the following loops would correctly add 1 to all but the first element in values? a. for (int j = 1; j < values.length; j++) values[j]++; b. for (int j = 0; j < values.length; j++) values[j]++; c. for (int j = 1; j < values.length - 1; j++) values[j]++; d. for (int j = 0; j < values.length - 1; j++) values[j]++; e. for (int j = values.length - 1; j >0; j--) values[j]++; f. for (int j = values.length; j >0; j--) values[j]++; g. for (int j = values.length; j >=0; j--) values[j]++; h. for (int j = values.length - 1; j >=0; j--) values[j]++; i. none of these

a, e

what is the output of the following java program? Class Driver { public static void main(String[] args) { foo(); bar(); } static void foo() { System.out.print("foo"); bar(); } static void bar () { System.out.print("bar"); } } a. barfoobar b. foobarbar c. foofoobar d. foobarfoo e. barbarfoo f. barfoofoo g. none of these

b

what is the output of the following java program? Class Driver { public static void main(String[] args) { int a = 0; int b = 8; while (a < b) { a = a + 2; b = b - 1; System.out.print("buz"); } System.out.print(a); } } a. buzbuzbuzbuz4 b. buzbuzbuz6 c. buzbuzbuzbuz6 d. buzbuzbuz8 e. buzbuzbuz5 f. none of these

b

given two String variables, s1 and s2, to determine if s1 is longer than s2, which of the following conditions would you use? a. (! s1.equals(s2)) b. (! s1.length().equals(s2)) c. (s1.length() > s2.length()) d. (s1.length() >= s2.length()) e. length(s1) != length(s2) f. none of these

c

what is the output of the following java program? Class Driver { public static void main(String[] args) { int a = 5; int b = 8; if (a<b) if (a * 2 > b) System.out.print("foo"); else System.out.print("bar"); else System.out.print("buz"); } } a. buz b. bar c. foo d. foobar e. foobuz f. barbuz e. none of these

c

when the following expression is evaluated, the result will be what Java data type? 3+5.0 a. int b. float c. double d. boolean e. char f. String g. none of the above

c

given the following declaration: int[] values = {2, 6, 0, 1, 4, 3, 5}; evaluate the expression: values[0]; a. -1 b. 0 c. 1 d. 2 e. 3 f. 4 g. 5 h. 6 i. 7 j. none of these

d

given the following declaration: String s = "Arizona_State_University"; Evaluate the expression: s.charAt(3) a. 'Ar' b. 'Ari' c. 'r' d. 'i' e. 'z' f. none of these

e

what is the output of the following java program? Class Driver { public static void main(String[] args) { int a = bar(3); int b = foo(a); System.out.print(b); } static int foo(int a) { System.out.print(a); a = bar (a+2); return a; } static int bar(int a) { System.out.print(a); return a+5; } } a. 3801015 b. 49914 c. 381515 d. 291414 e. 381015 f. 279914 g. none of these

e

which of the following would be the best data type for a variable to store a phone number? a. int b. float c. double d. boolean e. char f. String g. none of these

f

given the following declaration: int[] values = {2, 6, 0, 1, 4, 3, 5}; evaluate the expression: values[values[1]]; a. -1 b. 0 c. 1 d. 2 e. 3 f. 4 g. 5 h. 6 i. 7 j. none of these

g

what is the output for this java program? Class Driver { public static void main(String[] args) { int a = 1; int b = 0; for (int c = 1; c < 6; c++) { b = 1 while (b < c) { a = a + 1; b = b + a; } System.out.print(a); } System.out.print(b); } } a. 1234566 b. 234567 c. 012344 d. 12344 e. 12345 f. 001234 g. 012345 h. none of these

h

are Strings immutable in java? a. true b. false

true, once their declared you can't modify their contents


Ensembles d'études connexes

Recommended Maternal and Newborn Chapter 8: High-Risk Antepartum

View Set

Chapter 8 - Respiratory Function

View Set

The Heart Structures and Functions

View Set

Chapter IV Life Insurance Policy, Provisions, Options and Riders (15 Exam Questions)

View Set

S.O.A.P Subjective and Objective

View Set

Abeka Vocabulary Spelling Poetry V Review Quiz Four

View Set

Pearson My Programing Lab Python lab 6

View Set

United States Government and Politics

View Set