Deck 2: Data and Expressions

Full screen (f)
exit full mode
Question
Use the following class definition to answer the questions below.
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");
}
}
Consider the following statement: System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night");
This statement will output ________ lines of text

A) 1
B) 2
C) 3
D) 4
E) 5
Use Space or
up arrow
down arrow
to flip the card.
Question
Use the following class definition to answer the questions below.
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");
}
}
The program will print the word "Here" and then print

A) "There Everywhere" on the line after "Here"
B) "There" on the line after "Here" and "Everywhere" on the line after "There"
C) "There Everywhere" on the same line as "Here"
D) "ThereEverywhere" on the same line as "Here"
E) "ThereEverywhere" on the line after "Here"
Question
Given the following assignment statement, which of the following answers is True regarding the order that the operators will be applied based on operator precedence?
A = (b + c) * d / e - f;

A) *, /, +, -
B) *, +, /, -
C) +, *, /, -
D) +, /, *, -
E) +, -, *, /
Question
Use the following class definition to answer the questions below.
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");
}
}
The final println command will output

A) "But not in Texas"
B) "But notin Texas"
C) "But not" on one line and "in Texas" on the next line
D) "But not+in Texas"
E) "But not + in Texas"
Question
If x is an int and y is a float, all of the following are legal except which assignment statement?

A) y = x;
B) x = y;
C) y = (float) x;
D) x = (int) y;
E) all of the above are legal
Question
What is output with the statement System.out.println(""+x+y); if x and y are int values where x=10 and y=5?

A) 15
B) 105
C) 10 5
D) x+y
E) An error since neither x nor y is a String
Question
Use the following class definition to answer the questions below.
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");
}
}
If you want to output the text "hi there", including the quote marks, which of the following could do that?

A) System.out.println("hi there");
B) System.out.println(""hi there"");
C) System.out.println("\"hi there");
D) System.out.println("\"hi there\"");
E) none, it is not possible to output a quote mark because it is used to mark the beginning and ending of the String to be output
Question
What will be the result of the following assignment statement? Assume b = 5 and c = 10.
Int a = b * (-c + 2) / 2;

A) 30
B) -30
C) 20
D) -20
E) -6
Question
A Java variable is the name of a

A) numeric data value stored in memory
B) data value stored in memory that can not change during the program's execution
C) data value stored in memory that can change its value but cannot change its type during the program's execution
D) data value stored in memory that can change both its value and its type during the program's execution
E) data value or a class stored in memory that can change both its value and its type during the program's execution
Question
What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5?

A) 15
B) 105
C) 10 5
D) x+y
E) An error since neither x nor y is a String
Question
The word println is a(n)

A) method
B) reserved word
C) variable
D) class
E) String
Question
Consider having three String variables a, b, and c. The statement c = a + b; also can be achieved by saying

A) c = a.length( ) + b.length( );
B) c = (int) a + (int) b;
C) c = a.concat(b);
D) c = b.concat(a);
E) c = a.plus(b);
Question
Which of the following is True regarding the mod operator, %?

A) It can only be performed on int values and its result is a double
B) It can only be performed on int values and its result is an int
C) It can only be performed on float or double values and its result is an int
D) It can only be performed on float or double values and its result is a double
E) It can be performed on any numeric values, and the result always is numeric
Question
If you want to store into the String name the value "George Bush", you would do which statement?

A) String name = "George Bush";
B) String name = new String("George Bush");
C) String name = "George" + " " + "Bush";
D) String name = new String("George" + " " + "Bush");
E) Any of the above would work
Question
A cast is required in which of the following situations?

A) using charAt to take an element of a String and store it in a char
B) storing an int in a float
C) storing a float in a double
D) storing a float in an int
E) all of the above require casts
Question
Use the following class definition to answer the questions below.
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");
}
}
How many lines of output are provided by this program?

A) 1
B) 2
C) 3
D) 4
E) 5
Question
What value will z have if we execute the following assignment statement?
Float z = 5 / 10;

A) z will equal 0.0
B) z will equal 0.5
C) z will equal 5.0
D) z will equal 0.05
E) none of the above, a run-time error arises because z is a float and 5 / 10 is an int
Question
Use the following class definition to answer the questions below.
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");
}
}
A reasonable documentation comment for this program might be

A) // a program that demonstrates the differences between print, println and how + works
B) // a program that outputs a message about Texas
C) // a program that demonstrates nothing at all
D) // a program that outputs the message "Here There Everywhere But not in Texas"
E) // a program that contains three output statements
Question
Assume that x, y, and z are all integers (int) equal to 50, 20, and 6 respectively. What is the result of x / y / z?

A) 0
B) 12
C) 16
D) A syntax error as this is syntactically invalid
E) A run-time error because this is a division by 0
Question
Of the following types, which one cannot store a numeric value?

A) int
B) byte
C) float
D) char
E) all of these can store numeric values
Question
Which of the following would return the last character of the String x?

A) x.charAt(0);
B) x.charAt(last);
C) x.charAt(length(x));
D) x.charAt(x.length( )-1);
E) x.charAt(x.length( ));
Question
If you want to draw a red circle inside of a green square in an applet where the paint method is passed a Graphics object called page, which of the following sets of commands might you use?

A) page.setColor(Color.green); page.fillRect(50, 50, 100, 100);
Page.setColor(Color.red);
Page.fillOval(60, 60, 80, 80);
B) page.setColor(Color.red); page.fillOval(60, 60, 80, 80);
Page.setColor(Color.green);
Page.fillRect(50, 50, 100, 100);
C) page.setColor(Color.green); page.fillRect(60, 60, 80, 80);
Page.setColor(Color.red);
Page.fillOval(50, 50, 100, 100);
D) page.setColor(Color.red); page.fillOval(50, 50, 100, 100);
Page.setColor(Color.green);
Page.fillRect(60, 60, 80, 80);
E) any of the above would accomplish this
Question
For the following questions, refer to the class defined below:
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);
}
}
Questions33_34 computes

A) The correct average of x, y and z as a double
B) The correct average of x, y and z as an int
C) The average of x, y, and z as a double, but the result may not be accurate
D) the sum of x, y and z
E) the remainder of the sum of x, y and z divided by 3
Question
If a, b, and c are int variables with a = 5, b = 7, c = 12, then the statement int z = (a * b - c) / a; will result in z equal to

A) 0
B) 4
C) 5
D) -5
E) 23
Question
Which library package would you import to use the class Random?

A) java.beans
B) java.io
C) java.lang
D) java.text
E) java.util
Question
In order to create a constant, you would use which of the following Java reserved words?

A) private
B) static
C) int
D) final
E) class
Question
For the following questions, refer to the class defined below:
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);
}
}
What is output if x = 0, y = 1 and z = 1?

A) 0
B) 0.0
C) 0.6666666666666666
D) 0.6666666666666667
E) 0.67
Question
Assume that x is a double that stores 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%?

A) System.out.println(x);
B) System.out.println(nf);
C) System.out.println(nf.x);
D) System.out.println(nf.format(x));
E) System.out.println(format(x));
Question
The Random class has a method nextFloat( ) which returns a random float value between

A) -1 and +1
B) 0 and 1
C) 0 and 99
D) 1 and 100
E) -2,147,483,648 and +2,147,483,647
Question
Consider the following paint method and answer the questions below:
public void paint(Graphics page)
{
page.setColor(Color.blue);
page.fillRect(50, 50, 100, 100);
page.setColor(Color.white);
page.drawLine(50, 50, 150, 150);
page.drawLine(50, 150, 150, 50);
page.setColor(Color.black);
page.drawString("A nice box", 50, 170);
}
The String "A nice box" is drawn

A) above the box
B) to the left of the box
C) to the right of the box
D) below the box
E) inside the box
Question
Since you cannot take the square root of a negative number, you might use which of the following instructions to find the square root of the variable x?

A) Math.sqrt(x*x);
B) Math.sqrt((int) x);
C) Math.sqrt(Math.abs(x));
D) Math.abs(Math.sqrt(x));
E) Math.sqrt(-x);
Question
If you want to output a double so that at least 1 digit appears to the left side of the decimal point and exactly 1 digit appears to the right side of the decimal point, which pattern would you give a DecimalFormat variable when you instantiate it?

A) "0.0"
B) "0.#"
C) "0.0#"
D) "0.##"
E) "#.#"
Question
If the String major = "Computer Science", what is returned by major.charAt(1)?

A) 'C'
B) 'o'
C) 'm'
D) "C"
E) "Computer"
Question
Consider the following paint method and answer the questions below:
public void paint(Graphics page)
{
page.setColor(Color.blue);
page.fillRect(50, 50, 100, 100);
page.setColor(Color.white);
page.drawLine(50, 50, 150, 150);
page.drawLine(50, 150, 150, 50);
page.setColor(Color.black);
page.drawString("A nice box", 50, 170);
}
The figure drawn in this applet is

A) a blue square
B) a blue square with two white lines drawn horizontally through it
C) a blue square with two white lines drawn diagonally through it
D) a blue square with two white lines drawn vertically through it
E) a white square with two blue lines drawn vertically through it
Question
Which library package would you import to use NumberFormat and DecimalFormat?

A) java.beans
B) java.io
C) java.lang
D) java.text
E) java.util
Question
Using getCurrencyInstance( ) formats a variable, automatically inserting

A) decimal point for cents
B) dollar sign
C) percent sign
D) all three
E) A and B but not C
Question
Suppose that String name = "Frank Zappa". What will the instruction name.toUpperCase( ).replace('A', 'I'); return?

A) "FRANK ZAPPA "
B) "FRINK ZIPPI"
C) "Frink Zippi"
D) "Frank Zappa"
E) "FrInk ZIppI"
Question
Consider the double value likelihood = 0.013885. What would be output if DecimalFormat dformatter = DecimalFormat("0.00##"); and you execute System.out.println(df.format(likelihood)); ?

A) 0.013885
B) 0.0139
C) 0.014
D) )0139
E) )014
Question
What value will z have if we execute the following assignment statement?
Int z = 50 / 10.00;

A) 5
B) 5.0
C) 50
D) 10
E) none of the above, a run-time error arises because z is an int and 50 / 10.00 is not
Question
Consider the following paint method and answer the questions below:
public void paint(Graphics page)
{
page.setColor(Color.blue);
page.fillRect(50, 50, 100, 100);
page.setColor(Color.white);
page.drawLine(50, 50, 150, 150);
page.drawLine(50, 150, 150, 50);
page.setColor(Color.black);
page.drawString("A nice box", 50, 170);
}
You specify the shape of an oval in a Java applet by defining the oval's

A) arc locations
B) center and radius
C) bounding box
D) foci
E) none of the above, it is not possible to draw an oval in a Java applet
Question
Many Java drawing shapes are specified using a bounding rectangle.
Question
Java is a strongly typed language. What is meant by "strongly typed"?

A) Every variable must have an associated type before you can use it
B) Variables can be used without declaring their type
C) Every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type
D) Variables are allowed to change type during their existence in the program as long as the value it currently stores is of the type it is currently declared to be
E) Variables are allowed to change types during their existence in the program but only if the change is to a narrower type
Question
As presented in the Software Failure, the root cause of the Mars Climate Orbiter problem was

A) the cost of the project
B) an inability to track the orbiter at long distances
C) atmospheric friction
D) a communication issue between subsystems
E) none of the above
Question
The values of (double) 5 / 2 and (double) (5 / 2) are identical.
Question
Java is able to represent 255 * 255 * 255 = 16,581,375 distinct colors.
Question
Provide an example of how you might use a boolean, a float, a char, a String, and an int.
Question
If x is a string, then x = new String("OH"); and x = "OH"; will accomplish the same thing.
Question
A double is wider than a float and a float is wider than an int.
Question
If String name = "George W. Bush"; then the instruction name.length( ); will return 14.
Question
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( ).
Question
There are three ways that data conversion may occur by assignment, by promotion, by casting.
Question
You cannot cast a String to be a char and you cannot cast a String which stores a number to be an int, float or double.
Question
As explained in the Software Failure, the Mars Lander most likely crash landed when its descent engines cut off too high over the Mars surface.
Question
If x is the String "Hi There", then x.toUpperCase( ).toLowerCase( ); will return the original version of x.
Question
A variable of type boolean will store either a 0 or a 1.
Question
In Java, 'a' and 'A' are considered to be different values.
Question
If String a = "ABCD" and String b = "abcd" then a.equals(b); returns false but a.equalsIgnoreCase(b); returns True.
Question
Write a set of instructions to prompt the user for an int value and input it using the Scanner class into the variable x and prompt the user for a float value and input it using the Scanner class into the variable y.
Question
In order to generate a random number, you must use Math.random( ).
Question
The Java graphics coordinate system is similar to the coordinate system one finds in mathematics in every respect.
Question
Write a program that will input some number of cents (less than 100) and output the number of quarters, dimes, nickels and pennies needed to add up to that amount.
Question
Write the paint method for an applet so that it contains 4 concentric circles (each circle is inside the previous circle), where the largest circle is bounded by a 400x400 box and the smallest is bounded by a 100x100 box. Each circle is centered on an applet that is 400x400. Make each circle a different color of your choice.
Question
Write an assignment statement to compute the gas mileage of a car where the int values miles_traveled and gallons_needed have already been input. The variable gas_mileage needs to be declared and should be a double.
Question
How do the statements "import java.util.*;" and "import java.util.Random;" differ from each other?
Question
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);
}
}
Question
Assume that a = "1", b = "2", y = 3 and z = 4. How do the following two statements differ?
System.out.println(a + b + y + z);
System.out.println(y + z + a + b);
Question
Write an output statement which will output the following characters exactly as shown: / ' \" / ' \
Question
Provide three examples of code using assignment statements where one assignment statement would result in a syntax error, one would result in a logical error, and one would result in a run-time error.
Question
Using the various String methods, manipulate a String called current to be current's last character followed by the remainder of its characters in order, placing the result in a String called rearranged.
Question
Write a program which will input an int value x, and compute and output the values of 2ˣ and x¹⁰ as int values.
Question
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").
Question
What is wrong with the following assignment statement?
Assume x and y are both String objects.
String z = x.equals(y);
Question
An employer has decided to award a weekly pay raise to all employees by taking the square root of the difference between his weight and the employee's weight. For instance, an employee who weighs 16 pounds less than the employer will get a $4 per week raise. The raise should be in whole dollars (an int). Assume that employerWeight and employeeWeight are both int variables that have been input, write an assignment statement to compute the int value for raise.
Question
An applet is 200x200. Write the Strings "North", "South", "East", and "West" at the four edges of the applet where they should appear as if on a map. Use the color black for the text.
Question
Given two points in an applet represented by the four int variables x1, y1, x2 and y2, write a paint method to draw a line between the two points and write the location of the two points next to the two points.
Question
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.
Question
Explain, in words, what the following statement computes:
int z = (int) Math.ceil(Math.sqrt(x) / Math.sqrt(y));
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/77
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 2: Data and Expressions
1
Use the following class definition to answer the questions below.
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");
}
}
Consider the following statement: System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night");
This statement will output ________ lines of text

A) 1
B) 2
C) 3
D) 4
E) 5
B
Explanation: B) The \t escape sequence inserts a tab, but leaves the cursor on the same line. The \n escape sequence causes a new line to be produced so that "4 dinner" is output on the next line. The escape sequence \r causes the carriage to return (that is, the cursor to be moved back to the left margin) but because it does not start a new line, "2night" is output over "4 dinn" resulting in a second line that looks like "2nighter".
2
Use the following class definition to answer the questions below.
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");
}
}
The program will print the word "Here" and then print

A) "There Everywhere" on the line after "Here"
B) "There" on the line after "Here" and "Everywhere" on the line after "There"
C) "There Everywhere" on the same line as "Here"
D) "ThereEverywhere" on the same line as "Here"
E) "ThereEverywhere" on the line after "Here"
C
Explanation: C) System.out.print will output the word "Here" but will leave the cursor at that point rather than starting a new line. The next statement will output "There Everywhere" immediately after the word "Here". Since there is a blank space within the quote marks for "There", there is a blank space inserted between "There" and "Everywhere".
3
Given the following assignment statement, which of the following answers is True regarding the order that the operators will be applied based on operator precedence?
A = (b + c) * d / e - f;

A) *, /, +, -
B) *, +, /, -
C) +, *, /, -
D) +, /, *, -
E) +, -, *, /
C
Explanation: C) Order of precedence is any operator in ( ) first, followed by * and / in a left-to-right manner, followed by + and - in a left-to-right manner. So, + is first since it is in ( ), followed by * followed by / since * is to the left of /, followed finally by -. Both * and / are at the same level of precedence but evaluated left-to-right. The same is True of + and -.
4
Use the following class definition to answer the questions below.
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");
}
}
The final println command will output

A) "But not in Texas"
B) "But notin Texas"
C) "But not" on one line and "in Texas" on the next line
D) "But not+in Texas"
E) "But not + in Texas"
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
5
If x is an int and y is a float, all of the following are legal except which assignment statement?

A) y = x;
B) x = y;
C) y = (float) x;
D) x = (int) y;
E) all of the above are legal
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
6
What is output with the statement System.out.println(""+x+y); if x and y are int values where x=10 and y=5?

A) 15
B) 105
C) 10 5
D) x+y
E) An error since neither x nor y is a String
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
7
Use the following class definition to answer the questions below.
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");
}
}
If you want to output the text "hi there", including the quote marks, which of the following could do that?

A) System.out.println("hi there");
B) System.out.println(""hi there"");
C) System.out.println("\"hi there");
D) System.out.println("\"hi there\"");
E) none, it is not possible to output a quote mark because it is used to mark the beginning and ending of the String to be output
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
8
What will be the result of the following assignment statement? Assume b = 5 and c = 10.
Int a = b * (-c + 2) / 2;

A) 30
B) -30
C) 20
D) -20
E) -6
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
9
A Java variable is the name of a

A) numeric data value stored in memory
B) data value stored in memory that can not change during the program's execution
C) data value stored in memory that can change its value but cannot change its type during the program's execution
D) data value stored in memory that can change both its value and its type during the program's execution
E) data value or a class stored in memory that can change both its value and its type during the program's execution
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
10
What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5?

A) 15
B) 105
C) 10 5
D) x+y
E) An error since neither x nor y is a String
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
11
The word println is a(n)

A) method
B) reserved word
C) variable
D) class
E) String
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
12
Consider having three String variables a, b, and c. The statement c = a + b; also can be achieved by saying

A) c = a.length( ) + b.length( );
B) c = (int) a + (int) b;
C) c = a.concat(b);
D) c = b.concat(a);
E) c = a.plus(b);
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following is True regarding the mod operator, %?

A) It can only be performed on int values and its result is a double
B) It can only be performed on int values and its result is an int
C) It can only be performed on float or double values and its result is an int
D) It can only be performed on float or double values and its result is a double
E) It can be performed on any numeric values, and the result always is numeric
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
14
If you want to store into the String name the value "George Bush", you would do which statement?

A) String name = "George Bush";
B) String name = new String("George Bush");
C) String name = "George" + " " + "Bush";
D) String name = new String("George" + " " + "Bush");
E) Any of the above would work
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
15
A cast is required in which of the following situations?

A) using charAt to take an element of a String and store it in a char
B) storing an int in a float
C) storing a float in a double
D) storing a float in an int
E) all of the above require casts
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
16
Use the following class definition to answer the questions below.
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");
}
}
How many lines of output are provided by this program?

A) 1
B) 2
C) 3
D) 4
E) 5
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
17
What value will z have if we execute the following assignment statement?
Float z = 5 / 10;

A) z will equal 0.0
B) z will equal 0.5
C) z will equal 5.0
D) z will equal 0.05
E) none of the above, a run-time error arises because z is a float and 5 / 10 is an int
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
18
Use the following class definition to answer the questions below.
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");
}
}
A reasonable documentation comment for this program might be

A) // a program that demonstrates the differences between print, println and how + works
B) // a program that outputs a message about Texas
C) // a program that demonstrates nothing at all
D) // a program that outputs the message "Here There Everywhere But not in Texas"
E) // a program that contains three output statements
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
19
Assume that x, y, and z are all integers (int) equal to 50, 20, and 6 respectively. What is the result of x / y / z?

A) 0
B) 12
C) 16
D) A syntax error as this is syntactically invalid
E) A run-time error because this is a division by 0
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
20
Of the following types, which one cannot store a numeric value?

A) int
B) byte
C) float
D) char
E) all of these can store numeric values
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following would return the last character of the String x?

A) x.charAt(0);
B) x.charAt(last);
C) x.charAt(length(x));
D) x.charAt(x.length( )-1);
E) x.charAt(x.length( ));
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
22
If you want to draw a red circle inside of a green square in an applet where the paint method is passed a Graphics object called page, which of the following sets of commands might you use?

A) page.setColor(Color.green); page.fillRect(50, 50, 100, 100);
Page.setColor(Color.red);
Page.fillOval(60, 60, 80, 80);
B) page.setColor(Color.red); page.fillOval(60, 60, 80, 80);
Page.setColor(Color.green);
Page.fillRect(50, 50, 100, 100);
C) page.setColor(Color.green); page.fillRect(60, 60, 80, 80);
Page.setColor(Color.red);
Page.fillOval(50, 50, 100, 100);
D) page.setColor(Color.red); page.fillOval(50, 50, 100, 100);
Page.setColor(Color.green);
Page.fillRect(60, 60, 80, 80);
E) any of the above would accomplish this
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
23
For the following questions, refer to the class defined below:
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);
}
}
Questions33_34 computes

A) The correct average of x, y and z as a double
B) The correct average of x, y and z as an int
C) The average of x, y, and z as a double, but the result may not be accurate
D) the sum of x, y and z
E) the remainder of the sum of x, y and z divided by 3
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
24
If a, b, and c are int variables with a = 5, b = 7, c = 12, then the statement int z = (a * b - c) / a; will result in z equal to

A) 0
B) 4
C) 5
D) -5
E) 23
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
25
Which library package would you import to use the class Random?

A) java.beans
B) java.io
C) java.lang
D) java.text
E) java.util
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
26
In order to create a constant, you would use which of the following Java reserved words?

A) private
B) static
C) int
D) final
E) class
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
27
For the following questions, refer to the class defined below:
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);
}
}
What is output if x = 0, y = 1 and z = 1?

A) 0
B) 0.0
C) 0.6666666666666666
D) 0.6666666666666667
E) 0.67
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
28
Assume that x is a double that stores 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%?

A) System.out.println(x);
B) System.out.println(nf);
C) System.out.println(nf.x);
D) System.out.println(nf.format(x));
E) System.out.println(format(x));
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
29
The Random class has a method nextFloat( ) which returns a random float value between

A) -1 and +1
B) 0 and 1
C) 0 and 99
D) 1 and 100
E) -2,147,483,648 and +2,147,483,647
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
30
Consider the following paint method and answer the questions below:
public void paint(Graphics page)
{
page.setColor(Color.blue);
page.fillRect(50, 50, 100, 100);
page.setColor(Color.white);
page.drawLine(50, 50, 150, 150);
page.drawLine(50, 150, 150, 50);
page.setColor(Color.black);
page.drawString("A nice box", 50, 170);
}
The String "A nice box" is drawn

A) above the box
B) to the left of the box
C) to the right of the box
D) below the box
E) inside the box
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
31
Since you cannot take the square root of a negative number, you might use which of the following instructions to find the square root of the variable x?

A) Math.sqrt(x*x);
B) Math.sqrt((int) x);
C) Math.sqrt(Math.abs(x));
D) Math.abs(Math.sqrt(x));
E) Math.sqrt(-x);
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
32
If you want to output a double so that at least 1 digit appears to the left side of the decimal point and exactly 1 digit appears to the right side of the decimal point, which pattern would you give a DecimalFormat variable when you instantiate it?

A) "0.0"
B) "0.#"
C) "0.0#"
D) "0.##"
E) "#.#"
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
33
If the String major = "Computer Science", what is returned by major.charAt(1)?

A) 'C'
B) 'o'
C) 'm'
D) "C"
E) "Computer"
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
34
Consider the following paint method and answer the questions below:
public void paint(Graphics page)
{
page.setColor(Color.blue);
page.fillRect(50, 50, 100, 100);
page.setColor(Color.white);
page.drawLine(50, 50, 150, 150);
page.drawLine(50, 150, 150, 50);
page.setColor(Color.black);
page.drawString("A nice box", 50, 170);
}
The figure drawn in this applet is

A) a blue square
B) a blue square with two white lines drawn horizontally through it
C) a blue square with two white lines drawn diagonally through it
D) a blue square with two white lines drawn vertically through it
E) a white square with two blue lines drawn vertically through it
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
35
Which library package would you import to use NumberFormat and DecimalFormat?

A) java.beans
B) java.io
C) java.lang
D) java.text
E) java.util
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
36
Using getCurrencyInstance( ) formats a variable, automatically inserting

A) decimal point for cents
B) dollar sign
C) percent sign
D) all three
E) A and B but not C
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
37
Suppose that String name = "Frank Zappa". What will the instruction name.toUpperCase( ).replace('A', 'I'); return?

A) "FRANK ZAPPA "
B) "FRINK ZIPPI"
C) "Frink Zippi"
D) "Frank Zappa"
E) "FrInk ZIppI"
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
38
Consider the double value likelihood = 0.013885. What would be output if DecimalFormat dformatter = DecimalFormat("0.00##"); and you execute System.out.println(df.format(likelihood)); ?

A) 0.013885
B) 0.0139
C) 0.014
D) )0139
E) )014
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
39
What value will z have if we execute the following assignment statement?
Int z = 50 / 10.00;

A) 5
B) 5.0
C) 50
D) 10
E) none of the above, a run-time error arises because z is an int and 50 / 10.00 is not
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
40
Consider the following paint method and answer the questions below:
public void paint(Graphics page)
{
page.setColor(Color.blue);
page.fillRect(50, 50, 100, 100);
page.setColor(Color.white);
page.drawLine(50, 50, 150, 150);
page.drawLine(50, 150, 150, 50);
page.setColor(Color.black);
page.drawString("A nice box", 50, 170);
}
You specify the shape of an oval in a Java applet by defining the oval's

A) arc locations
B) center and radius
C) bounding box
D) foci
E) none of the above, it is not possible to draw an oval in a Java applet
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
41
Many Java drawing shapes are specified using a bounding rectangle.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
42
Java is a strongly typed language. What is meant by "strongly typed"?

A) Every variable must have an associated type before you can use it
B) Variables can be used without declaring their type
C) Every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type
D) Variables are allowed to change type during their existence in the program as long as the value it currently stores is of the type it is currently declared to be
E) Variables are allowed to change types during their existence in the program but only if the change is to a narrower type
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
43
As presented in the Software Failure, the root cause of the Mars Climate Orbiter problem was

A) the cost of the project
B) an inability to track the orbiter at long distances
C) atmospheric friction
D) a communication issue between subsystems
E) none of the above
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
44
The values of (double) 5 / 2 and (double) (5 / 2) are identical.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
45
Java is able to represent 255 * 255 * 255 = 16,581,375 distinct colors.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
46
Provide an example of how you might use a boolean, a float, a char, a String, and an int.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
47
If x is a string, then x = new String("OH"); and x = "OH"; will accomplish the same thing.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
48
A double is wider than a float and a float is wider than an int.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
49
If String name = "George W. Bush"; then the instruction name.length( ); will return 14.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
50
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( ).
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
51
There are three ways that data conversion may occur by assignment, by promotion, by casting.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
52
You cannot cast a String to be a char and you cannot cast a String which stores a number to be an int, float or double.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
53
As explained in the Software Failure, the Mars Lander most likely crash landed when its descent engines cut off too high over the Mars surface.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
54
If x is the String "Hi There", then x.toUpperCase( ).toLowerCase( ); will return the original version of x.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
55
A variable of type boolean will store either a 0 or a 1.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
56
In Java, 'a' and 'A' are considered to be different values.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
57
If String a = "ABCD" and String b = "abcd" then a.equals(b); returns false but a.equalsIgnoreCase(b); returns True.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
58
Write a set of instructions to prompt the user for an int value and input it using the Scanner class into the variable x and prompt the user for a float value and input it using the Scanner class into the variable y.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
59
In order to generate a random number, you must use Math.random( ).
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
60
The Java graphics coordinate system is similar to the coordinate system one finds in mathematics in every respect.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
61
Write a program that will input some number of cents (less than 100) and output the number of quarters, dimes, nickels and pennies needed to add up to that amount.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
62
Write the paint method for an applet so that it contains 4 concentric circles (each circle is inside the previous circle), where the largest circle is bounded by a 400x400 box and the smallest is bounded by a 100x100 box. Each circle is centered on an applet that is 400x400. Make each circle a different color of your choice.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
63
Write an assignment statement to compute the gas mileage of a car where the int values miles_traveled and gallons_needed have already been input. The variable gas_mileage needs to be declared and should be a double.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
64
How do the statements "import java.util.*;" and "import java.util.Random;" differ from each other?
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
65
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);
}
}
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
66
Assume that a = "1", b = "2", y = 3 and z = 4. How do the following two statements differ?
System.out.println(a + b + y + z);
System.out.println(y + z + a + b);
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
67
Write an output statement which will output the following characters exactly as shown: / ' \" / ' \
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
68
Provide three examples of code using assignment statements where one assignment statement would result in a syntax error, one would result in a logical error, and one would result in a run-time error.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
69
Using the various String methods, manipulate a String called current to be current's last character followed by the remainder of its characters in order, placing the result in a String called rearranged.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
70
Write a program which will input an int value x, and compute and output the values of 2ˣ and x¹⁰ as int values.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
71
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").
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
72
What is wrong with the following assignment statement?
Assume x and y are both String objects.
String z = x.equals(y);
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
73
An employer has decided to award a weekly pay raise to all employees by taking the square root of the difference between his weight and the employee's weight. For instance, an employee who weighs 16 pounds less than the employer will get a $4 per week raise. The raise should be in whole dollars (an int). Assume that employerWeight and employeeWeight are both int variables that have been input, write an assignment statement to compute the int value for raise.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
74
An applet is 200x200. Write the Strings "North", "South", "East", and "West" at the four edges of the applet where they should appear as if on a map. Use the color black for the text.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
75
Given two points in an applet represented by the four int variables x1, y1, x2 and y2, write a paint method to draw a line between the two points and write the location of the two points next to the two points.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
76
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.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
77
Explain, in words, what the following statement computes:
int z = (int) Math.ceil(Math.sqrt(x) / Math.sqrt(y));
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 77 flashcards in this deck.