Chapter 2 : Java Fundamentals

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

Which of the following is NOT a legal identifier?

7thheaven

Of the following variable names, which is the best one for keeping track of whether an integer might be prime or not?

mightBePrime

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

monthlyPay

Primitive data types

next

Write a complete program whose class name is Hello and that displays Hello, world on the screen.

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

The character escape sequence to force the cursor to go to the next line is:

\n

The character escape sequence to force the cursor to advance forward to the next tab setting is:

\t

Which of the following IS a legal identifier?

____________

Write a literal representing the integer value zero.

0

Which of the following names in a program is equivalent to the name int?

None of the above

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.print(\"Turing, Alan\");

Given an integer variable count, write a statement that displays the value of count on the screen.

System.out.print(count);

Assume that word is a String variable. Write a statement to display the message "Today's Word-Of-The-Day is: " followed by the value of word. The message and the value of word should appear together, on a single line on standard output.

System.out.println("Today's Word-Of-The-Day is: " + word);

Write a single statement that will print the message "first is " followed by the value of first, and then a space, followed by "second = ", followed by the value of second. Print everything on one line and go to a new line after printing. Assume that first has already been declared as a double and that second has been declared as an int. Assume also that the variables have already been given values.

System.out.println("first is " + first + " second = " + second);

The exercise instructions here are LONG -- please read them all carefully. If you see an internal scrollbar to the right of these instructions, be sure to scroll down to read everything. Given an integer variable i and a floating-point variable f, that have already been given values, write a statement that writes both of their values to standard output in the following format: i=value-of-i f=value-of-f Thus, if i's value were 25 and f's value were 12.34, the output would be: i=25 f=12.34 But you don't know what i's value and f's value are. They might be 187 and 24.06. If that's what their values are, the output from your statement should be: i=187 f=24.06 On the other hand, they might be 19 and 2.001. If that's what their values are, the output from your statement should be: i=19 f=2.001 Remember: you are GIVEN i and f-- that means they are already declared and they already have values! Don't change their values by assigning or initializing them! Just print them out the way we have shown above. Just write one statement to produce the output. Remember: in your output you must be displaying both the name of the variable (like i) and its value.

System.out.println("i=" + i + " f=" + f);

Given a floating point variable fraction, write a statement that displays the value of fraction on the screen. Do not display anything else on the screen-- just the value of fraction.

System.out.println(fraction);

Assume that message is a String variable. Write a statement to display its value on standard output.

System.out.println(message);

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.

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

The character escape sequence to represent a double quote is:

\"

The character escape sequence to represent a single quote is:

\'

The character escape sequence to represent a backslash is:

\\

Of the following variable names, which is the best one for keeping track of whether a patient has a fever or not?

hasFever

In Java, an argument is

information provided to a method.

Before a variable is used it must be

declared

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

drivingAge = 17;

Declare an integer variable named degreesCelsius.

int degreesCelsius;

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

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

Suppose your name was George Gershwin. Write a complete main method that would print your last name, followed by a comma, followed by a space and your first name.

public static void main(String[] args) { System.out.println(\"Gershwin, George\"); }

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

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


Kaugnay na mga set ng pag-aaral

Living with art 11th edition chapter 21

View Set

Nutrition and Diet Therapy BOIL-1322 Exam 4

View Set

GEOG 1000- Quiz 8: Cultural Geography; Population and Migration

View Set

Dudek Chapter 19: Nutrition for Patients with Diabetes Mellitus

View Set

Chapter 6: Reporting and Analyzing Cash, Fraud, and Internal Control

View Set

Unit 27: Real Estate Commission & License Law

View Set