CSA Test Retake Studying

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/15

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

16 Terms

1
New cards

What is the order of operations in Java?

It follows PEMDAS

2
New cards

Which of the following codes will assign 5 to the variable number and why?

I. int number = 79/15;

II. int number = 30 / 3 / (-3 + 5);

III. int number = 20 + 4/6 + 1

I and II only - I works because when 79/15 is performed, the number is 5.266667 - while this is a decimal, since the data type of number is an int, it will automatically assign the whole number value to the variable, which is 5. II also works because if the order of operations is followed, 5 is the answer. III is not valid because by following order of operations the answer would be 21.66667 - the integer number of this would still be 21, which is not 5.

3
New cards

What will be printed by the code segment below and why?

int first = 5;

int second = 10;

System.out.println(“t” + 9 + 1 + “ “);

System.out.println(“Go” + second + 5 + “ “);

System.out.println(second + first + “End”);

t91 Go105 15End. This is the answer because you must consider order of operations with the operations. Because 9 is added to String value “t”, the new value is a String: “t9”. Then 1 is added to “t9”, making the entire new value “t91”. It works similarly for the second line, the numbers are added first to a String. For the last line, however, a number is first added to a number, so the actual numerical value will be the new value when first and second are combined. Then finally, the String value is added to the end of that numerical value.

4
New cards

Which of the following statements would evaluate to 8.0?

Math.pow(2, 2) * Math.pow(2, 2) / 2;

5
New cards

Consider the following line of code:

int randomNumber = (int) (Math.random) ()* 20 + 2)

What are the possible values for the variable randomNumber?

All integers from 2 - 22 (not including 22).

The second number in the statement (2) represents the smallest possible number that the variable can be. Adding the first number in the statement (20) to the second number (2) in the statement represents the largest possible value that the variable can be (NOT inclusive). So in this case, the variable can hold a value from 2-22, but not including 22. (so basically 2-21)

6
New cards

What symbol creates comments in Java?

//

7
New cards

Write code which will calculate the volume of the sphere given the following formula:

V = 4/3 pi r³

Use the following variables representing the radius of the sphere, and pi. Store the answer in a variable called volume.

double pi = 3.1415;

double radius = 8.6;

double volume = (4.0/3.0 times pi) times (Math.pow(radius, 3));

you MUST write the numbers as 4.0 and 3.0 and NOT 4 and 3, because if you do so the numbers will simplify to an integer which would yield a different answer.

8
New cards

What is casting?

The process of converting one data type to another.

9
New cards

What is the value of var after executing the following statement?

double var = 12 / 5

2.0

Because the numbers in the variable are integers, the answer will simplify to just 2, but because it is stored in a double the answer will specifically be 2.0.

10
New cards

geometric mean question

III only. double value = v1 * v2; double geoMean = value.sqrt();

11
New cards

Consider the following code segment:

String oldStr = “ABCDEF”;

String newStr = old.Str.substring(1, 3) + oldStr.substring(4);

System.out.println(newStr);

What is the output?

BCEF; remember the 1st number shows where to start (inclusive), the second number shows the stopping point (NOT inclusive)

12
New cards

Book object question - Which of the following is the correct way to create an instance of the Book class?

Book myBook = new Book(“1984”, “George Orwell”);

13
New cards

Which of the following is true about overloading methods?

Defining multiple methods in the same class with the same name but different parameter lists.

14
New cards

output of same class code question

remember with the value of length, just start counting at 1, index does not matter. for substrings and indexes the index does matter.

15
New cards

Without showing the implementation write two methods which are overloaded and will compile without error:

public static int method(int x, int y);

{

}

public static String method(String a, String b);

{

}

To show overloaded methods that will compile without error, the parameters of each method must be different in some way. So the data types of the parameters in the second method must be different (int in the first method, String in the second), or the number of parameters must be different from the first method.

16
New cards

Consider the following code: (long bookStore code) and create two bookStoreReceipt objects, assuming they are in the main class.

BookstoreReceipt book1 = new BookstoreReceipt(“Keethu,” 19, “Thank you.”);

BookstoreReceipt book2 = new BookstoreReceipt(“Veronica,” 16, “Happy reading!”);