JAVA

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Assume y is a properly initialized positive integer. Which of the following will always result in a value of 1?

y /= y;

What is returned by this method call: translator("pokemon")? public String translator(String word) { return word.substring(1) + word.charAt(0) + "ay"; }

"okemonpay"

What will this code return given checkMethod(false, true)? public int checkMethod(boolean x, boolean y) { if(!x) { if(y) { return -1; } else { return 1; } } else { return 0; } }

-1

What is the result of this expression? 4 + 8 * 3 / 4 + 5 % 2

11

What will the value of myBankAccount be after the method call depositMoney(myBankAccount, 572);? int myBankAccount = 122; public void depositMoney(int bankAccount, int deposit) { bankAccount += deposit; }

122

What will the following code print? int n = 5; n ++; n ++; n += n; System.out.println(n);

14

What does this method call doubleNumber(7.8); return, given the following method? public double doubleNumber(double myNumber) { return (double) (int) myNumber * 2; }

14.0

Given the following, what will be printed out? int a = 2; int b = 3; int c = 4; System.out.println(a * b + b / a + (a * c / 4.0) * c);

15.0

What will this method call print to the screen? public static void formatText(int a, int b, String c) { System.out.println(b + " " + c + ", " + a); } formatText(2018, 17, "Dec")

17 Dec, 2018

How many lines will be printed with the following statement? System.out.println("Hello"); System.out.println(" World"); System.out.print("Welcome to"); System.out.print("Java.");

3

Assume that a, b, and c are all integers with values of 90, 5, and 4 respectively. What would the value of x be in this expression? int x = a / b / c;

4

What is the value of x after this code runs? int x = 5; x = 10; x = 4;

4

What is the result of the following expression when x is 125?x % 6

5

What is the value of myInteger after this line of code is executed? int myInteger = (int) 5.6;

5

What is the result of this expression? (int) (5 + 2 / 3 + 1)

6

The following code is intended to print 8. int x = 23; double y = 3; System.out.println((int)(x / y)); What is printed and why?

7 becausex / y calculates to 7.66 then the cast to an int results in the value getting truncated to 7

Which expression returns the 1's place of an integer x?

x % 10

What will the output of the following lines of code be? int x = 10; int y = x / 4; System.out.print("x + y = "); System.out.print(x + y);

x + y = 12

UNIT3

Boolean Expressions and If Statements

What does the method call tripleString("APCSA"); return for the following method? public String tripleString(String x) { return x * 3; }

This method is improperly written.

Unit2

Using Objects

What output will be produced by System.out.println("Hello"); System.out.println("Karel");

Hello Karel

Which of the following would equal 2? I. int x = 0; x ++; x += x; II. int y = 4; y ++; y /= 2; III. int z = 4; z += 2; z /= 2;

I and II Only

Which of the following print: Hello Java! I. System.out.println("Hello Java!"); II. System.out.print("Hello Java!"); III. System.out.print("Hello"); System.out.print("Java!"); IV. System.out.println("Hello"); System.out.println("Java!");

I and II only

Why do we use methods in Java? I. To make code easier to understandII. To define global variablesIII. To avoid repeated codeIV. To simplify codeV. To avoid needing to define them as public or private

I, III, and IV

A financial planner wants to calculate the average rate of return for clients. She does this by dividing the earnedIncome by the principal amount and displays the value as a double. Which of the following will correctly calculate and store the returnRate, assuming earnedIncome and principal are integers? I. double returnRate = earnedIncome / principal;II. double returnRate = (double) earnedIncome / principal;III. double returnRate = (double) (earnedIncome / principal);

II only

What is true of a void method?

It returns no value.

What is wrong with this method definition? public int printPayAmount(int amount) { System.out.println(amount); }

Nothing is returned from this method

Unit 1

Primitive Types

Which of the following is not a primitive type?

String

What are parameters?

The formal names given to the data that gets passed into a method.

Which of the following statements is true about variables?

The memory associated with a variable of a primitive type holds an actual primitive value.

The value that a non-void method outputs is called

a return value.

Refer to the following code segment: double myDouble = 1/4; System.out.println("1 / 4 = " + myDouble); The output of the code is: 1 / 4 = 0.0 The student wanted the output to be: 1 / 4 = 0.25 Which change to the first line of their code segment would get the student the answer that they wanted?

double myDouble = (double) 1/4;

What is the proper syntax to declare and initialize a variable called temperature to have the value 70.4?

double temperature = 70.4;

Given a and b as properly initialized integers, which of the following will result in a correct calculation with a decimal answer?

double y = 1.0 * a / b;

Joe's Pizza is creating a program that will calculate the total amount of money an employee earns each week. Employees are paid by the hour and only work in 1 hour increments. Salaries start at minimum wage, but employees get a $0.50 raise after the first month. Which variables would be the best to store the hours and salary of the employees?

int hours double salary

A teacher has calculated the gradeAverage as a double, but for report cards, she needs to report it rounded to the nearest whole number. Assuming that we round up from 0.5, which of the following will correctly round the gradeAverage?

int rcGrade = (int) (gradeAverage + 0.5);

A procedure that is defined by the user is called a

method.

A science teacher wants to create an Elements class for the Periodic Table. They want to include several attributes to the Elements class: the atomic weight, the Element name, and the atomic number for the element. Which of the following instance variables makes the most sense based on these attributes?

private double atomicWeight; private String name; private int atomicNum;

A coffee shop has created a DrinkOrder class. The class contains variables to represent the following: A String variable called name to represent the name of the drink. An int variable called ounces to indicate how many ounces the drink should be. A boolean variable called isIced to indicate whether the drink is iced. An object Latte has been declared as type DrinkOrder after someone has ordered a Latte. Based on the information provided, which would be the most accurate class declaration for the DrinkOrder class?

public class DrinkOrder { private String name; private int ounces; private boolean isIced; public DrinkOrder(String theName, int theOunces, boolean hasIce) { name = theName; ounces = theOunces; isIced = hasIce; } }

Which of the following values can correctly be saved in a boolean?

true


Kaugnay na mga set ng pag-aaral

Cloud Computing Final Exam: Chapter 1-10

View Set

Psychosomatic Diseases and Stress-Related Physical Ailments

View Set

Chapter 2 - Strategy of Compensation Plans

View Set