Java: Chapter 2

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

String empty = "";

Declare a String variable named empty, and initialize it to the empty String.

char c;

Declare a character variable named c.

double netWeight;

Declare a double variable named netWeight.

boolean isACustomer;

Declare a variable isACustomer suitable for representing a true or false value.

final int MONTHS_IN_YEAR = 12;

Declare an integer constant, MONTHS_IN_YEAR, whose value is 12.

int cardsInHand = 13;

Declare an integer variable cardsInHand and initialize it to 13.

int degreesCelsius;

Declare an integer variable named degreesCelsius.

double length = 3.5, width = 1.55;

Declare two double variables, one named length with a value of 3.5 and the other named width with a value of 1.55.

int profitStartOfQuarter; int cashFlowEndOfYear;

Declare two integer variables named profitStartOfQuarter and cashFlowEndOfYear.

line1 = stdin.nextLine();

Given a String variable named line1 and given a Scanner reference variable stdin that has been assigned a reference to a Scanner object, read the next line from stdin and save it in line1. (Do not concern yourself with any possible exceptions here-- assume they are handled elsewhere.)

bridgePlayers = bridgePlayers + 4;

Given an integer variable bridgePlayers, write a statement that increases the value of that variable by 4.

System.out.println(count);

Given an integer variable count, write a statement that displays the value of count on the screen. Do not display anything else on the screen -- just the value of count.

drivingAge = 17;

Given an integer variable drivingAge that has already been declared, write a statement that assigns the value 17 to drivingAge.

12 * pricePerCase

Given the variable pricePerCase, write an expression corresponding to the price of a dozen cases.

fullAdmissionPrice - discountAmount

Given the variables fullAdmissionPrice and discountAmount (already declared and assigned values), write an expression corresponding to the price of a discount admission.

firstName + " " + middleName + " " + lastName

Given three String variables that have been declared and given values, firstName, middleName, and lastName, write an expression whose value is the values of each these variables joined by a single space. So if firstName, middleName, and lastName, had the values "Big", "Bill", and "Broonzy", the expression's value would be "Big Bill Broonzy". Alternatively, if firstName, middleName, and lastName, had the values "Jerry", "Lee", and "Lewis", the expression's value would be "Jerry Lee Lewis".

-information provided to a method

In Java, an argument is -a logical sequence of statements proving the correctness of a program. -information that a method returns to its caller. -information provided to a method. -a verbal dispute.

public class Q { public static void main(String[] a) { System.out.println("Q"); } }

Rearrange the following code so that it forms a correct program that prints out the letter Q:

System.out.println("Turing, Alan");

Suppose your name was Alan Turing. Write a statement that would print your last name, followed by a comma, followed by a space and your first name.

System.out.println(num + " " + cost + " ");

Two variables, num and cost have been declared and given values: num is an integer and cost is a double. Write a single statement that outputs num and cost to standard output. Print both values (num first, then cost), separated by a space on a single line that is terminated with a newline character. Do not output any thing else.

monthlyPay

Which is the best identifier for a variable to represent the amount of money your boss pays you each month? notEnough wages paymentAmount monthlyPay money

7thheaven

Which of the following is NOT a legal identifier? outrageouslyAndShockinglyLongRunon _42 _ lovePotionNumber9 7thheaven

public static void main(String[] args) { System.out.print("Hello, world"); }

Write a complete main method that prints Hello, world to the screen.

1.5

Write a literal corresponding to the floating point value one-and-a-half.

false

Write a literal representing the false value.

System.out.println("Hello, world");

Write a statement that prints Hello, world to the screen.

temperature = stdin.nextDouble();

Write a statement that reads a floating point value from standard input into temperature. Assume that temperature. has already been declared as an double variable. Assume also that stdin is a variable that references a Scanner object associated with standard input.

(exam1 + exam2) / 2

Write an expression that computes the integer average of the int variables exam1 and exam2 (both declared and assigned values).

verbalScore + mathScore

Write an expression that computes the sum of two variables verbalScore and mathScore (already declared and assigned values).

String win, place, show;

Write the declaration of three String variables named win, place, and show.


Set pelajaran terkait

MKTG Research exam 2 ch. 12 quiz

View Set

Psych 111 - Chapter 1 Practice Quizzes

View Set

Chapter 4: Intro to Criminal Justice

View Set

Unit 3, Lesson 1: What is matter made of?

View Set

Driver's Education Chapter 3.4 Pavement Markers

View Set

personal money midterm chapter 4

View Set

"A Separate Peace" -- Study Guide Questions & Answers -- Chapters 1-5

View Set