CompSciFinalExam

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Identify all Java code elements below that are related to the conditional building block in a Java program

&& switch if, else, else if

What syntax do we use to indicate a multi-line comment in Java?

/*

What syntax do we use to indicate a 1 line comment in Java?

//

How many times does the print occur? boolean valid = false; String today = "Wednesday"; int a = 5; while (!valid) { if (today.equals("Wednesday")) { valid = true; continue; } a++; System.out.println(a); }

0

What is in variable a, rounded to 2 decimal places, after completing the following? double a = 89%3;

2.0

What value is in b after completing the following Java syntax? int a = 5;int b = a++ * ++a;

30

What value is in a after completing the following Java syntax? int a = 5;int b = ++a * a--;

5

Which of the following allows me to expand or contract storage without fully replacing?

ArrayList

What data type do we rely on to consider alternate execution paths inside Java programs?

BOOLEAN

Complete Java syntax below to declare a variable of type character named letter, and assign the value A. [ fill this in ] letter = 'A';

Char

For a variable nums that represents an integer array, mark all that apply for nums.

Default value of elements is 0 and nums is a reference variable

Scanner aligns with which of the programming building blocks?

Input

When we run Java code in Eclipse, the .java file is converted to a stream of 0's and 1's. What do we call the interface layer that allows the resulting binary code to run on any computer, regardless of operating system?

JVM

Complete Java syntax to convert String "5" to an appropriate numeric value and store it invariable num. long num = [ fill this in ]("5");

Long.parseLong("5")

Which of the following Java elements align with the expressions building block?

Math.PI * / %

I ran the following Java code. Which of the following explains what occurred? short a = 120;short b = 75 - 25*3;if (b!=0 && a%b != 0) System.out.println("b is not divisor of a");

No error, no message, b is a divisor of a

What return type should we indicate when creating object constructor?

No return type

You have been asked to write code to swap the value at position 4 with the value 2 positions from end of String array vals. What data type should you declare for the temporary variable needed to complete this process?

String

I want to return formatted string output from a method that will contain a mix of strings, integer, floating point, and other values. For floating point values, I want to control the number of decimal places. For integer, I want to control the width. Which option below would be best solution?

String.format()

Complete Java syntax to convert boolean variable valid to String data type. String s = [ fill this in ](valid);

String.valueOf(valid);

Complete the Java syntax to extract the characters from string s String s = "Testing what you know"; System.out.println( ... ); DESIRED RESULT: ing wh

System.out.println(s.substring(4, 10) )

Correct the Java syntax in the last line below; currently I have an error. float a; 0double b = 2929.3939; a = b;

a =(float)b;

Complete the following Java syntax to evaluate the contents of variable a. The printshould only work when a is a multiple of 5. if ( ... ) { System.out.println(a); }

a%5==0

What do we call the values that are provided to a method as part of the method call?

aguremnets

How do we indicate code that is grouped together for a method, or a conditional, or a class in Java?

block

What type of variable is theNumber below? public class RandomGuess { public void genNumber() { for (int i=0; i < 10; i++) { int theNumber; Random num = new Random(); theNumber = num.nextInt(100) + 1; } } public String checkGuess(int guess) { ...

block variable

What Java syntax enables us to leave a loop, and not execute any remaining commands in the loop body?

break

Complete the Java syntax to retrieve the character t from String s String s = "One, two, again"; System.out.println( ... );

charAt(indexOf("t"));

What operation is performed by the second + in the following Java syntax? String s = "how is it going?" + 1 + 2 + 3;System.out.println(s);

concatenation

What Java syntax enables us to return to top of loop, complete iteration statement, and execute body of loop again?

continue

What type of loop would be most appropriate to identify the maximum value in the variable nums? int [] nums = {57, 34, 23, 15, 42, 87};

definite what version

What type of loop would be most appropriate to display the array nums in reverse? int [] nums = {57, 34, 23, 15, 42, 87};

definite, where version

Identify all Java code elements below that are related to the iteration building block in a Java program.

for (int i=0; i<10; i++) while (false) do ... while (true)

For which variables, would we typically create getters/setters?

instance variables

What value is displayed? String [] words = new String [4]; System.out.println(words[2]);

null

For a variable num that represents a local integer variable, mark all that apply

num is primitive variable

I am creating a class BankTeller that I will use to create multiple objects. There are several pieces of information each object should know about themselves. For example, name, window #, notary, experience level. What keyword should I include to ensure name is not visible outside the object? String name

private

If I do not want a class method or class variable to be visible outside the class, what keyword do I add to the declaration?

private

Which of the following are stored as 1D arrays inside a 2D array

rows

For a variable s that represents a String, mark all that apply specific to s.

s must be initialized,s can be converted to an array of characters

I have 2 String variables s1 and s2. Complete Java syntax to compare s1 and s2 to see if the contents are the same. s1[ fill this in ](s2);

s1.equals(s2);

This is a review question in preparation for final exam: What do we call the sort process by which an array is searched for the smallest or largest element, moves that element to front or back of array, and then continues with the next smallest or largest element? HINT: look at the deck on arrays, and then find sorting algorithms at back of deck.

selection

I am creating a class BankTeller that I will use to create multiple objects. There are several pieces of information each object should know about themselves. For example, name, window #, notary, experience level. I created a constructor that takes 4 parameters: name, window, notary, exper. When I try to initialize the instance variables, I get an error. What keyword should I include in order to address this error? private String name; private int window; private boolean notary; private String exper; public BankTeller(String name, int window, boolean notary, String exper) {

this

I am creating a class BankTeller that I will use to create multiple objects. Which of the following should I include in my class to provide means for objects to be printed once created?

toString method

Complete the Java syntax to retrieve the number 86 from the array nums int [] nums = {33, 45, 89, 72, 86}; System.out.println( ... );

nums[4];

What do we call the variables listed in a method definition that will contain copies of values provided when the method is called?

parameters

For a variable words that represents a String array, mark all that apply

words has a defined size and words is reference variable

Which of the following can I use to instantiate a Java object?

Random Scanner String

I completed the following Java syntax. Which of the following explain the result? String s1 = "This is a string"; String s2 = s1 + ""; System.out.println(s1==s2);

Strings stored in JVM are at different memory addresses

This is a review question in preparation for final exam: What do we call the sort process by which an array is traversed, swapping smallest or largest for every pair of elements, then repeating the process until no swaps are completed HINT: look at the deck on arrays, and then find sorting algorithms at back of deck.

bubble

I am creating a class BankTeller that I will use to create multiple objects. Which of the following should I include in my class to provide means for Java code to compare two objects of type BankTeller?

equals method

What do we call the process by which Java JVM reclaims memory when object is set to null?

garbage collection

Select all that apply.. I ran the following Java code. Which of the following explain the result? System.out.println('[' - 'c'); RESULT: -8

'[' occurs before 'c' char has Unicode equivalent for all characters

Correct the Java syntax to assign the value 5.8 to variable num float num = [ fill this in ];

(float)5.8;

What type of loop would be most appropriate to prompt for input, validate the input, display error messages, and continue until input is valid?

indefinite, one execution guaranteed

Complete the Java syntax to produce the desired result. String s = "TestIng sOmE mOrE";System.out.println("First e from end found at position");if (s.toLowerCase().contains("e")) { System.out.println( ... );}

indexof(e)


Set pelajaran terkait

Chapter 21: Teacher and Counselor

View Set