Consider the following code segment. String greet1 = “Good morning!”;String greet2 = “Good afternoon!”;String greet3 = “Good evening”;int timeOfDay;if(timeOfDay >= 1700) { System.out.println(greet3);}else if(timeOfDay >= 1200) { System.out.println(greet2);}else { System.out.println(greet1);} What is printed as a result of executing the code segment if timeOfDay equals 1230?
Category: Uncategorized
Consider the following class definition. The class does not…
Consider the following class definition. The class does not compile. public class Player{ private double score; public getScore() { return score;}// Constructor not shown} The accessor method getScore is intended to return the score of a Player object. Which of the following best explains why the class does not compile?
Which assignment operator would you use to add 5 to a variab…
Which assignment operator would you use to add 5 to a variable x?
The AnimalPrinter class includes the following two methods….
The AnimalPrinter class includes the following two methods. AnimalPrinter Class Method Signature Explanation public void printDog() Prints the word “dog” and then moves the cursor to a new line. public void printCat() Prints the word “cat” and then moves the cursor to a new line. The method myMethod appears in a class other than AnimalPrinter. The method is intended to produce the following output. dog cat Assume that an AnimalPrinter object myPrinter has been properly declared and initialized inside myMethod. Which of the following code segments, if located in myMethod, will produce the intended output?
An import java.lang.Math; statement is required to use metho…
An import java.lang.Math; statement is required to use methods of the Math class.
Write an if statement for the problem below. Use meaningful…
Write an if statement for the problem below. Use meaningful variable names. You can assume that the variables you use are declared and have been initialized. If the difference between variables temp1 and temp2 is more than 2.3, set the variable approx to (temp1 – temp2) * factor.
Consider the following Boolean expressions. I. A && B …
Consider the following Boolean expressions. I. A && B II. !A && B Which of the following best describes the relationship between values produced by expression I and expression II?
Given the following declarations: int i = 15; short s = 25;…
Given the following declarations: int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25; Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error. i = f * 2;
Consider the following code segment. String one = “compute…
Consider the following code segment. String one = “computer”; String two = “science”;String concat = /* missing code */; System.out.println(concat); Which of the following expressions can be used to replace /* missing code */ so that the code segment prints the string “pun”?
What is the result of 17 % 5 when evaluated in a Java expr…
What is the result of 17 % 5 when evaluated in a Java expression? If it shows an error, just type ‘error.’