Exam 2: Data and Expressions

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Which of the following is true regarding the mod operator, %?

Free
(Multiple Choice)
4.9/5
(43)
Correct Answer:
Verified

E

Assume that x and y are ints equal to 10 and 5 respectively. What is the output of the following statement? System.out.println(x + y);

Free
(Multiple Choice)
4.8/5
(29)
Correct Answer:
Verified

A

As explained in the Software Failure section in the text, the Mars Lander most likely crash landed when its descent engines cut off too high over the Mars surface.

Free
(True/False)
4.9/5
(34)
Correct Answer:
Verified

True

What are the syntax errors from the following program? public class Enigma { public static void main(String[] args) { System.out.println("Input a String"); String x = scan.nextString(); int size = x.length; char last = x.charAt(size); System.out.println("The last character in your string ", x, " is ", last); } }

(Essay)
4.8/5
(34)

If you want to output a double so that at least one digit appears to the left side of the decimal point and exactly one digit appears to the right side, which pattern would you give a DecimalFormat variable when you instantiate it?

(Multiple Choice)
5.0/5
(32)

What will be the result of the following assignment statement, given that b = 5 and c = 10? int a = b * (-c + 2)/2;

(Multiple Choice)
4.9/5
(36)

Unlike the String class where you must pass a message to an object (instance) of the class, as in x.length(), in order to use either the Scanner or Math classes, you pass messages directly to the class name, as in Math.abs()or scan.nextInt().

(True/False)
4.8/5
(30)

Write a program which will input an int value, x, and compute and output the values of 2^x and x^10 as int values.

(Essay)
5.0/5
(39)

Java is a strongly typed language. What is meant by "strongly typed"?

(Multiple Choice)
4.8/5
(40)

Given three int variables with the values a = 5, b = 7, and c = 12, what is the value of z after the following statement is executed? int z = (a * b - c) / a;

(Multiple Choice)
4.8/5
(41)

How many ways are there to test to see if two String variables, a and b, are equal to each other if we ignore their case (for instance, "aBCd" would be considered equal to "ABcd")?

(Essay)
4.8/5
(30)

Write an assignment statement to compute the gas mileage of a car where the int values milesTraveled and gallonsNeeded have already been input. The variable gasMileage needs to be declared and should be a double.

(Essay)
4.8/5
(30)

Given four int values, x1, x2, y1, y2, write the code to compute the distance between the two points (x1, y1) and (x2, y2), storing the result in the double distance.

(Essay)
4.8/5
(32)

The following statement will output __________ lines of text. System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 Dinner\r2night");

(Multiple Choice)
5.0/5
(28)

The Random class has a method, nextFloat() which returns a random float value between

(Multiple Choice)
4.9/5
(40)

Example Code Ch 02-2 import java.util.Scanner; public class Questions33_34 { public static void main(String[] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt(); System.out.println("Enter another integer value"); y = scan.nextInt(); System.out.println("Enter a third integer value"); z = scan.nextInt(); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } -Refer to Example Code Ch 02-2. What is the output if x = 0, y = 1, and z = 1?

(Multiple Choice)
4.8/5
(38)

Given String name = "Arleen Crabtree". What will the following instruction return? name.toUpperCase().replace('R', 'Z');

(Multiple Choice)
4.9/5
(27)

If x is a String, then x = new String("OH"); and x = "OH"; will accomplish the same thing.

(True/False)
4.9/5
(37)

Example Code Ch 02-1 public class Questions1_4 { public static void main(String[] args) { System.out.print("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas"); } } -Refer to the class definition in Example Code Ch 02-1. The final println command will output

(Multiple Choice)
4.9/5
(43)

Given x is a double and has the value 0.362491. To output this value as 36%, you could use the NumberFormat class with: NumberFormat nf = NumberFormat.getPercentInstance(); Which of the following statements then would output x as 36%?

(Multiple Choice)
4.7/5
(39)
Showing 1 - 20 of 67
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)