The StringBuilder constructor used in the following statement will
StringBuilder str = new StringBuilder(25);
~~~Give the object, str, 25 bytes of storage and not store anything in them
What will be the value of str after the following statements are executed?
StringBuilder str =
new StringBuilder("We have lived in Chicago, " +
"Trenton, and Atlanta.");
str.replace(17, 24, "Tampa");
~~~~We have lived in Tampa, Trenton, and Atlanta.
What will be the tokens in the following statement?
StringTokenizer strToken = new StringTokenizer("123-456-7890",
"-", true);
~~~123, 456, 7890, and -
If you do not specify delimiters in the StringTokenconstructor, which of the following cannot be a delimiter?
~~~Semicolon
What will be the tokens in the following statement?
String str = "red$green&blue#orange";
String tokens = str.split("[$&#]");
~~~"red", "green", "blue"and "orange"
If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one for each delimiter character.
~~false
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);
~~~diddl
StringBuilder objects are not immutable.
~~true
What will be the value of matches after the following code has been executed?
boolean matches;
String str1 = "The cow jumped over the moon.";
String str2 = "moon";
matches = str1.endsWith(str2);
~~~false
If str is declared as
String str = "ABCDEFGHI";
what will be returned fromCharacter.toLowerCase(str.charAt(5))?
~~f
The String class’s valueOf() method accepts a string representation as an argument and returns its equivalent integer value.
~~False
What will be the value of loc after the following code is executed?
int loc;
String str = "The cow jumped over the moon.";
loc = str.lastIndexOf("ov", 14);
~~-1
What does the following statement do?
Float number = new Float(8.8);
~~All of the above
To convert the string, str = "285" to an int, use the following statement
~~int x = Integer.parseInt(str);
What will be the value of loc after the following code is executed?
int loc;
String str = "The cow jumped over the moon.";
loc = str.indexOf("ov");
~~. 15
The following statement correctly creates aStringBuilder object.
StringBuilder str = "Caesar Salad";
~~false
What would be the results of executing the following code?
StringBuilder str = new StringBuilder(12);
str.append("The cow");
str.append(" jumped over the ");
str.append("moon.");
~~strbuff would equal "The cow jumped over the moon."
Two ways of concatenating two Strings are
~~Use the concat() method or use the + between the two Strings
The following statement correctly creates aStringBuilder object.
StringBuilder str = "Caesar Salad";
==false
If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one for each delimiter character.
==flase
What will be printed after the following code is executed?
String str = "abc456";
int m = 0;
while ( m < 6 )
{
if (!Character.isLetter(str.charAt(m)))
System.out.print(
Character.toUpperCase(str.charAt(m)));
m++;
}
==456
Which of the following statements will print the maximum value a double variable may have?
==System.out.println(Double.MAX_VALUE);
To convert the int variable, number to a string, use the following statement.
==String str = Integer.toString(number);
The no-arg constructor for a StringBuilder object gives the object enough storage space to hold this many characters.
=16 characters
aprilxmassey
Saturday, May 7, 2011
chapter 9
When an object reference is passed to a method, the method may change the values in the object.
==true
You cannot use the fully-qualifed name of an enum constant for this.
==a case expression***
Look at the following declaration.
enum Tree { OAK, MAPLE, PINE }
What is the ordinal value of the MAPLE enum constant?
==1
If the this variable is used as a constructor call,
=A compiler error will result, if it is not the first statement of the constructor
A class's static methods do not operate on the fields that belong to any instance of the class.
==true
If you have defined a class SavingsAccount with a public static method getNumberOfAccounts(), and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts()method?
==SavingsAccount.getNumberOfAccounts();
The JVM periodically performs this process to remove unreferenced objects from memory.
==garbage collection
If the following is from the method section of a UML diagram, which of the following statements is true?
+ equals(object2:Stock) : boolean
==This is a public method that accepts a FeetInches object as its argument and returns a boolean value
You may use this to compare two enum data values.
==The equals and compareTo methods that automatically come with the enum data type
Look at the following declaration.
enum Tree { OAK, MAPLE, PINE }
What is the fully-qualified name of the PINE enum constant?
==Tree.PINE
If the this variable is used as a constructor call,
==A compiler error will result if it is not the first statement of the constructor
To copy an object to another object of the same class
==Write a copy method that will make a field by field copy of the two objects
Enumerated types have this method, which returns the position of an enum constant in the declaration list.
==ordinal
If you have defined a class named SavingsAccountwith a public static data member namednumberOfAccounts, and created a SavingsAccountobject referenced by the variable account20, which of the following will assign numberOfAccounts tonumAccounts?
==numAccounts = SavingsAccount.numberOfAccounts;
When a method's return type is a class, what is actually returned to the calling program?
==A reference to an object of that class
The only limitation that static methods have is
==They cannot refer to non-static members of the class
When the this variable is used to call a constructor,
==. It must be the first statement in the constructor making the call
You can declare an enumerated data type inside of a method.
==false
The term for the relationship created by object aggregation is
==Has a
If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent:
System.out.println(object1);
System.out.println(object1.toString());
~~true
You cannot use the fully-qualifed name of an enum constant for this
~~a case expression
To compare two objects
~~Write an equals method that will make a field by field comparison of the two object
What will be returned from a method, if the following is the method header:
public Rectangle getRectangle()
~~The address of an object in the class Rectangl
An instance of a class does not have to exist in order for values to be stored in a class's static fields
~~~true
If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string.
~~true
Which of the following is not true about static methods?
~~They are called from an instance of the class.
==true
You cannot use the fully-qualifed name of an enum constant for this.
==a case expression***
Look at the following declaration.
enum Tree { OAK, MAPLE, PINE }
What is the ordinal value of the MAPLE enum constant?
==1
If the this variable is used as a constructor call,
=A compiler error will result, if it is not the first statement of the constructor
A class's static methods do not operate on the fields that belong to any instance of the class.
==true
If you have defined a class SavingsAccount with a public static method getNumberOfAccounts(), and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts()method?
==SavingsAccount.getNumberOfAccounts();
The JVM periodically performs this process to remove unreferenced objects from memory.
==garbage collection
If the following is from the method section of a UML diagram, which of the following statements is true?
+ equals(object2:Stock) : boolean
==This is a public method that accepts a FeetInches object as its argument and returns a boolean value
You may use this to compare two enum data values.
==The equals and compareTo methods that automatically come with the enum data type
Look at the following declaration.
enum Tree { OAK, MAPLE, PINE }
What is the fully-qualified name of the PINE enum constant?
==Tree.PINE
If the this variable is used as a constructor call,
==A compiler error will result if it is not the first statement of the constructor
To copy an object to another object of the same class
==Write a copy method that will make a field by field copy of the two objects
Enumerated types have this method, which returns the position of an enum constant in the declaration list.
==ordinal
If you have defined a class named SavingsAccountwith a public static data member namednumberOfAccounts, and created a SavingsAccountobject referenced by the variable account20, which of the following will assign numberOfAccounts tonumAccounts?
==numAccounts = SavingsAccount.numberOfAccounts;
When a method's return type is a class, what is actually returned to the calling program?
==A reference to an object of that class
The only limitation that static methods have is
==They cannot refer to non-static members of the class
When the this variable is used to call a constructor,
==. It must be the first statement in the constructor making the call
You can declare an enumerated data type inside of a method.
==false
The term for the relationship created by object aggregation is
==Has a
If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent:
System.out.println(object1);
System.out.println(object1.toString());
~~true
You cannot use the fully-qualifed name of an enum constant for this
~~a case expression
To compare two objects
~~Write an equals method that will make a field by field comparison of the two object
What will be returned from a method, if the following is the method header:
public Rectangle getRectangle()
~~The address of an object in the class Rectangl
An instance of a class does not have to exist in order for values to be stored in a class's static fields
~~~true
If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string.
~~true
Which of the following is not true about static methods?
~~They are called from an instance of the class.
Friday, May 6, 2011
chapter 8
What will be the value of x[1] after the following code is executed?
int[] x = { 22, 33, 44 };
arrayProcess(x);
...
public static void arrayProcess(int[] a)
{
for(int k = 0; k < 3; k++)
{
a[k] = a[k] + 5;
}
}
==38
A ragged array is
==A two-dimensional array when the rows are of different lengths
What will be the value of x[8] after the following code has been executed?
final int SUB = 12;
int[] x = new int[SUB];
int y = 20;
for(int i = 0; i < SUB; i++)
{
x[i] = y;
y += 5;
}
====60
What would be the results of the following code?
int[] array1 = new int[25];
… // Code that will put values in array1
int value = array1[0];
for (int a = 1; a < array1.length; a++)
{
if (array1[a] < value)
value = array1[a];
}
==value contains the lowest value in array1
What would be the results after the following code was executed?
int[] x = {23, 55, 83, 19};
int[] y = {36, 78, 12, 24};
for(int a = 0; a < x.length; a++)
{
x[a] = y[a];
y[a] = x[a];
}
===x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
What will be the value of x[8] after the following code has been executed?
final int SUB = 12;
int[] x = new int[SUB];
int y = 100;
for(int i = 0; i < SUB; i++)
{
x[i] = y;
y += 10;
}
===180
If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?
==
for (int row = 0; row < numbers.length; row++)
{
for (int col = 0; col < numbers[row].length; col++)
total += numbers[row][col];
}
What would be the results after the following code was executed?
int[] x = {23, 55, 83, 19};
int[] y = {36, 78, 12, 24};
x = y;
y = x;
===x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
What would be the results of the following code?
int[] x = { 55, 33, 88, 22, 99,
11, 44, 66, 77 };
int a = 10;
if(x[2] > x[5])
a = 5;
else
a = 8;
== a = 5
If a[] and b[] are two integer arrays, the expression a == b compares the array contents.
==false
Given the following two-dimensional array declaration, which statement is true?
int [][] numbers = new int [6] [9];
~~The array numbers has 6 rows and 9 columns
What does the following statement do?
double[] array1 = new double[10];
~~All of the above
The sequential search algorithm
~~Uses a loop to sequentially step through an array, starting with the first element
Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.
~true
Java does not limit the number of dimensions that an array may have.
~true
The binary search algorithm
~~Will cut the portion of the array being searched in half each time the loop fails to locate the search value
What will be the value of x[1] after the following code is executed?
int[] x = {22, 33, 44};
arrayProcess(x[1]);
...
public static void arrayProcess(int a)
{
a = a + 5;
}
~~33
An ArrayList object automatically expands in size to accommodate the items stored in it.
~true
The following statement creates an ArrayListobject. What is the purpose of the notation?
ArrayList<String> arr = new ArrayList<String>();
~**It specifies that only String objects may be stored in the ArrayList object.
What would be the results of the following code?
final int SIZE = 25;
int[] array1 = new int[SIZE];
... // Code that will put values in array1
int value = 0;
for (int a = 0; a < array1.length; a++)
{
value += array1[a];
}
~~~***value contains the sum of all the values in array1
Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement
==str[0].toUpperCase();
In memory, an array of String objects
===Consists of an array of references to Stringobjects
For the following code, what would be the value ofstr[2]?
String[] str = {"abc", "def", "ghi", "jkl"};
==A reference to the String "ghi"
What will be the result of executing the following code?
int[] x = {0, 1, 2, 3, 4, 5};
==An array of 6 values ranging from 0-5 and referenced by the variable x will be created
You can use this ArrayList class method to insert an item at a specific location in an ArrayList.
==add
What will be the value of x[8] after the following code has been executed?
final int SUB = 12;
int[] x = new int[SUB];
int y = 100;
for(int i = 0; i < SUB; i++)
{
x[i] = y;
y += 10;
}
==180
In order to do a binary search on an array,
===The array must first be sorted in ascending order
You can use this ArrayList class method to replace an item at a specific location in anArrayList.
==set
This ArrayList class method deletes an item from an ArrayList.
===remove
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.
==true
int[] x = { 22, 33, 44 };
arrayProcess(x);
...
public static void arrayProcess(int[] a)
{
for(int k = 0; k < 3; k++)
{
a[k] = a[k] + 5;
}
}
==38
A ragged array is
==A two-dimensional array when the rows are of different lengths
What will be the value of x[8] after the following code has been executed?
final int SUB = 12;
int[] x = new int[SUB];
int y = 20;
for(int i = 0; i < SUB; i++)
{
x[i] = y;
y += 5;
}
====60
What would be the results of the following code?
int[] array1 = new int[25];
… // Code that will put values in array1
int value = array1[0];
for (int a = 1; a < array1.length; a++)
{
if (array1[a] < value)
value = array1[a];
}
==value contains the lowest value in array1
What would be the results after the following code was executed?
int[] x = {23, 55, 83, 19};
int[] y = {36, 78, 12, 24};
for(int a = 0; a < x.length; a++)
{
x[a] = y[a];
y[a] = x[a];
}
===x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
What will be the value of x[8] after the following code has been executed?
final int SUB = 12;
int[] x = new int[SUB];
int y = 100;
for(int i = 0; i < SUB; i++)
{
x[i] = y;
y += 10;
}
===180
If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?
==
for (int row = 0; row < numbers.length; row++)
{
for (int col = 0; col < numbers[row].length; col++)
total += numbers[row][col];
}
What would be the results after the following code was executed?
int[] x = {23, 55, 83, 19};
int[] y = {36, 78, 12, 24};
x = y;
y = x;
===x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
What would be the results of the following code?
int[] x = { 55, 33, 88, 22, 99,
11, 44, 66, 77 };
int a = 10;
if(x[2] > x[5])
a = 5;
else
a = 8;
== a = 5
If a[] and b[] are two integer arrays, the expression a == b compares the array contents.
==false
Given the following two-dimensional array declaration, which statement is true?
int [][] numbers = new int [6] [9];
~~The array numbers has 6 rows and 9 columns
What does the following statement do?
double[] array1 = new double[10];
~~All of the above
The sequential search algorithm
~~Uses a loop to sequentially step through an array, starting with the first element
Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.
~true
Java does not limit the number of dimensions that an array may have.
~true
The binary search algorithm
~~Will cut the portion of the array being searched in half each time the loop fails to locate the search value
What will be the value of x[1] after the following code is executed?
int[] x = {22, 33, 44};
arrayProcess(x[1]);
...
public static void arrayProcess(int a)
{
a = a + 5;
}
~~33
An ArrayList object automatically expands in size to accommodate the items stored in it.
~true
The following statement creates an ArrayListobject. What is the purpose of the notation?
ArrayList<String> arr = new ArrayList<String>();
~**It specifies that only String objects may be stored in the ArrayList object.
What would be the results of the following code?
final int SIZE = 25;
int[] array1 = new int[SIZE];
... // Code that will put values in array1
int value = 0;
for (int a = 0; a < array1.length; a++)
{
value += array1[a];
}
~~~***value contains the sum of all the values in array1
Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement
==str[0].toUpperCase();
In memory, an array of String objects
===Consists of an array of references to Stringobjects
For the following code, what would be the value ofstr[2]?
String[] str = {"abc", "def", "ghi", "jkl"};
==A reference to the String "ghi"
What will be the result of executing the following code?
int[] x = {0, 1, 2, 3, 4, 5};
==An array of 6 values ranging from 0-5 and referenced by the variable x will be created
You can use this ArrayList class method to insert an item at a specific location in an ArrayList.
==add
What will be the value of x[8] after the following code has been executed?
final int SUB = 12;
int[] x = new int[SUB];
int y = 100;
for(int i = 0; i < SUB; i++)
{
x[i] = y;
y += 10;
}
==180
In order to do a binary search on an array,
===The array must first be sorted in ascending order
You can use this ArrayList class method to replace an item at a specific location in anArrayList.
==set
This ArrayList class method deletes an item from an ArrayList.
===remove
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.
==true
chapter 7
Which of the following is not a rule for the FlowLayout manager?
==All of the above are rules for the FlowLayout manager
You would use this command at the operating system command line to execute the code in the MyApplication class and display the graphic image Logo.jpg as a splash screen.
==java -splash:Logo.jpg MyApplication
When an application uses many components, instead of deriving just one class from the JFrame class, a better approach is to
==Encapsulate smaller groups of related components and their event listeners into their own classes
When this is the argument passed to the JFrame class's setDefaultCloseOperation() method, the application is hidden, but not closed.
==B. JFrame. HIDE_ON_CLOSE**
In Java, the ability to display splash screens was introduced in Java 6.
==true
When an application uses many components, rather than deriving just one class from the JFrame class, it is often better to encapsulate smaller groups of related components and their event listeners into their own class. A commonly used technique to do this is
==To derive a class from the JPanel class to contain other components and their related code
If button1 is a JButton object, which of the following statements will make its background blue
==button1.setBackground(Color.blue);
To click the JRadioButton referenced by radio, write the following code.
==radio.doClick();
The FlowLayout manager does not allow the programmer to align components.
==false
When a splash screen is displayed, the application does not load and execute until the user clicks the splash screen image with the mouse.
==true
==All of the above are rules for the FlowLayout manager
You would use this command at the operating system command line to execute the code in the MyApplication class and display the graphic image Logo.jpg as a splash screen.
==java -splash:Logo.jpg MyApplication
When an application uses many components, instead of deriving just one class from the JFrame class, a better approach is to
==Encapsulate smaller groups of related components and their event listeners into their own classes
When this is the argument passed to the JFrame class's setDefaultCloseOperation() method, the application is hidden, but not closed.
==B. JFrame. HIDE_ON_CLOSE**
In Java, the ability to display splash screens was introduced in Java 6.
==true
When an application uses many components, rather than deriving just one class from the JFrame class, it is often better to encapsulate smaller groups of related components and their event listeners into their own class. A commonly used technique to do this is
==To derive a class from the JPanel class to contain other components and their related code
If button1 is a JButton object, which of the following statements will make its background blue
==button1.setBackground(Color.blue);
To click the JRadioButton referenced by radio, write the following code.
==radio.doClick();
The FlowLayout manager does not allow the programmer to align components.
==false
When a splash screen is displayed, the application does not load and execute until the user clicks the splash screen image with the mouse.
==true
chapter 6
Instance methods do not have the key word static in their headers.
==true
Which of the following statements will create a reference, str, to the string, “Hello, world”?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
==Both 1 and 2
It is common practice in object-oriented programming to make all of a class's
==fields private
Another term for an object of a class is a(n)
== instance
One or more objects may be created from a(n)________.
==class
This refers to the combining of data and code into a single object.
==Encapsulation
Which of the following statements will create a reference, str, to the String, "Hello, World"?
==String str = “Hello, World”;
Given the following code, what will be the value of finalAmount when it is displayed?
public class Order
{
private int orderNum;
private double orderAmount;
private double orderDiscount;
public Order(int orderNumber, double orderAmt,
double orderDisc)
{
orderNum = orderNumber;
orderAmount = orderAmt;
orderDiscount = orderDisc;
}
public int getOrderAmount()
{
return orderAmount;
}
public int getOrderDisc()
{
return orderDisc;
}
}
public class CustomerOrder
{
public static void main(String[] args)
{
int ordNum = 1234;
double ordAmount = 580.00;
double discountPer = .1;
Order order;
double finalAmount = order.getOrderAmount() —
order.getOrderAmount() * order.getOrderDisc();
System.out.println("Final order amount = $" +
finalAmount);
}
}
====There is no value because the object order has not been created
The following package is automatically imported into all Java programs.
==java.lang
The scope of a private instance field is
==the instance methods of the same class
Look at the following statement.
import java.util.*;
This is an example of
==A wildcard import
In a UML diagram to indicate the data type of a variable enter
==The variable name followed by a colon and the data type
When an object is created, the fields associated with the object are called
==instance fields
In your textbook the general layout of a UML diagram is a box that is divided into three sections. The top section has the _________; the middle section holds _________; the bottom section holds _________.
==Class name; fields; methods
A constructor is a method that is automatically called when an object is created.
==true
It is common practice in object-oriented programming to make all of a class's
==fields private
The following package is automatically imported into all Java programs
==java.lang
After the header, the body of the method appears inside a set of
==Braces, {}
A UML diagram does not contain ________.
==object names
What does the following UML diagram entry mean?
+ setHeight(h : double) : void
~~This is a public method with a parameter of data type double and does not return a value
In UML diagrams, this symbol indicates that a member is public.
~~ +
A class’s responsibilities include
~Both A and B
For the following code, which statement is not true?
public class Circle
{
private double radius;
public double x;
private double y;
}
~~~y is available to code that is written outside the Circle class
==true
Which of the following statements will create a reference, str, to the string, “Hello, world”?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
==Both 1 and 2
It is common practice in object-oriented programming to make all of a class's
==fields private
Another term for an object of a class is a(n)
== instance
One or more objects may be created from a(n)________.
==class
This refers to the combining of data and code into a single object.
==Encapsulation
Which of the following statements will create a reference, str, to the String, "Hello, World"?
==String str = “Hello, World”;
Given the following code, what will be the value of finalAmount when it is displayed?
public class Order
{
private int orderNum;
private double orderAmount;
private double orderDiscount;
public Order(int orderNumber, double orderAmt,
double orderDisc)
{
orderNum = orderNumber;
orderAmount = orderAmt;
orderDiscount = orderDisc;
}
public int getOrderAmount()
{
return orderAmount;
}
public int getOrderDisc()
{
return orderDisc;
}
}
public class CustomerOrder
{
public static void main(String[] args)
{
int ordNum = 1234;
double ordAmount = 580.00;
double discountPer = .1;
Order order;
double finalAmount = order.getOrderAmount() —
order.getOrderAmount() * order.getOrderDisc();
System.out.println("Final order amount = $" +
finalAmount);
}
}
====There is no value because the object order has not been created
The following package is automatically imported into all Java programs.
==java.lang
The scope of a private instance field is
==the instance methods of the same class
Look at the following statement.
import java.util.*;
This is an example of
==A wildcard import
In a UML diagram to indicate the data type of a variable enter
==The variable name followed by a colon and the data type
When an object is created, the fields associated with the object are called
==instance fields
In your textbook the general layout of a UML diagram is a box that is divided into three sections. The top section has the _________; the middle section holds _________; the bottom section holds _________.
==Class name; fields; methods
A constructor is a method that is automatically called when an object is created.
==true
It is common practice in object-oriented programming to make all of a class's
==fields private
The following package is automatically imported into all Java programs
==java.lang
After the header, the body of the method appears inside a set of
==Braces, {}
A UML diagram does not contain ________.
==object names
What does the following UML diagram entry mean?
+ setHeight(h : double) : void
~~This is a public method with a parameter of data type double and does not return a value
In UML diagrams, this symbol indicates that a member is public.
~~ +
A class’s responsibilities include
~Both A and B
For the following code, which statement is not true?
public class Circle
{
private double radius;
public double x;
private double y;
}
~~~y is available to code that is written outside the Circle class
chapter 5
When writing the documentation comments for a method, you can provide a description of each parameter by using a
==@param tag
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " +
product);
}
== showProduct(3.3, 55);
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
==showProduct(10, 4.5);
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
==The last line of code will cause an error
What is wrong with the following method call?
displayValue (double x);
==The data type of the argument x should not be included in the method call
You must have a return statement in a value-returning method.
==true
Breaking a program down into small manageable methods
==all of the above
The header of a value-returning method must specify this.
==The data type of the return value
This part of a method is a collection of statements that are performed when the method is executed.
=Method body
In the following code, System.out.println(num), is an example of ________.
double num = 5.4;
System.out.println(num);
num = 0.0;
==A void method
No statement outside the method in which a parameter variable is declared can access the parameter by its name.
==true
Which of the following is not a part of the method header?
==semicolon
A parameter variable's scope is the method in which the parameter is declared.
==true
When an object, such as a String, is passed as an argument, it is
==Actually a reference to the object that is passed
Which of the following is not a benefit derived from using methods in programming?
==. All of the above are benefits
Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause.
==true
All @param tags in a method's documentation comment must
==Appear after the general description of the method
Given the following method header, which of the method calls would be an error?
public void displayValues(double x, int y)
==displayValue(a,b); // where a is a short and b is a long
To document the return value of a method, use this in a documentation comment.
==The @return tag
A value-returning method can return a reference to a non-primitive type.
==true
When an argument value is passed to a method, the receiving parameter variable is
==Declared in the method header inside the parentheses
Constants, variables, and the values of expressions may be passed as arguments to a method.
==true
This type of method performs a task and then terminates.
==void
Which of the following is not a benefit derived from using methods in programming?
==All of the above are benefits
No statement outside the method in which a parameter variable is declared can access the parameter by its name.
==true
The expression in a return statement can be any expression that has a value.
==true
==@param tag
Which of the following would be a valid method call for the following method?
public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " +
product);
}
== showProduct(3.3, 55);
Which of the following would be a valid method call for the following method?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
==showProduct(10, 4.5);
What will be the result of the following code?
int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
==The last line of code will cause an error
What is wrong with the following method call?
displayValue (double x);
==The data type of the argument x should not be included in the method call
You must have a return statement in a value-returning method.
==true
Breaking a program down into small manageable methods
==all of the above
The header of a value-returning method must specify this.
==The data type of the return value
This part of a method is a collection of statements that are performed when the method is executed.
=Method body
In the following code, System.out.println(num), is an example of ________.
double num = 5.4;
System.out.println(num);
num = 0.0;
==A void method
No statement outside the method in which a parameter variable is declared can access the parameter by its name.
==true
Which of the following is not a part of the method header?
==semicolon
A parameter variable's scope is the method in which the parameter is declared.
==true
When an object, such as a String, is passed as an argument, it is
==Actually a reference to the object that is passed
Which of the following is not a benefit derived from using methods in programming?
==. All of the above are benefits
Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause.
==true
All @param tags in a method's documentation comment must
==Appear after the general description of the method
Given the following method header, which of the method calls would be an error?
public void displayValues(double x, int y)
==displayValue(a,b); // where a is a short and b is a long
To document the return value of a method, use this in a documentation comment.
==The @return tag
A value-returning method can return a reference to a non-primitive type.
==true
When an argument value is passed to a method, the receiving parameter variable is
==Declared in the method header inside the parentheses
Constants, variables, and the values of expressions may be passed as arguments to a method.
==true
This type of method performs a task and then terminates.
==void
Which of the following is not a benefit derived from using methods in programming?
==All of the above are benefits
No statement outside the method in which a parameter variable is declared can access the parameter by its name.
==true
The expression in a return statement can be any expression that has a value.
==true
chapter 4
In a for loop, the control variable can only be incremented.
==true..
Before entering a loop to compute a running total, the program should first
==Set the accumulator where the total will be kept to an initial value, usually zero
What will be the values of x and y as a result of the following code?
int x = 12, y = 5;
x += y- -;
==x = 17, y = 4
When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.
==false
In the for loop, the control variable cannot be initialized to a constant value and tested against a constant value.
==false
A loop that repeats a specific number of times is known as a(n) ________.
==Counter-controlled loop
This is a sum of numbers that accumulates with each iteration of a loop
==Running total
This is an item that separates other items.
==Delimiter
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
==true
If a loop does not contain within itself a way to terminate, it is called
==An infinite loop
Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?
==int number = inputFile.nextInt();*****
A loop that executes as long as a particular condition exists is called a(n) ________.
==Conditional loop
A for loop normally performs which of these steps?
==All of the above**
What will be the value of x after the following code is executed?
int x = 10;
for (int y = 5; y < 20; y +=5)
x += y;
==40
The do-while loop is a pre-test loop.
==false
The do-while loop must be terminated with a semicolon.
==true
Look at the following code:
Scanner keyboard = new Scanner(System.in);
int studentGrade = 0;
int totalOfStudentGrades = 0;
while(studentGrade != -1)
{
System.out.println("Enter student grade: :");
studentGrade = keyboard.nextInt();
totalOfStudentGrades += studentGrade;
}
In the loop header: while(studentGrade != -1), what is the purpose of "-1"
====It is a sentinel
This is a value that signals when the end of a list of values has been reached.
==Sentinel
When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.
==false
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x <= 100);
===5
What will be the values of x and y as a result of the following code?
int x = 25, y = 8;
x += y++;
==x = 33, y = 9
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
}
==This is an infinite loop
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x > 100);
==1
This type of loop is ideal in situations where the exact number of iterations is known.
==for loop
Which of the following will open a file named MyFile.txt and allow you to read data from it?
==File file = new File("MyFile.txt");
Scanner inputFile = new Scanner(file);
==true..
Before entering a loop to compute a running total, the program should first
==Set the accumulator where the total will be kept to an initial value, usually zero
What will be the values of x and y as a result of the following code?
int x = 12, y = 5;
x += y- -;
==x = 17, y = 4
When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.
==false
In the for loop, the control variable cannot be initialized to a constant value and tested against a constant value.
==false
A loop that repeats a specific number of times is known as a(n) ________.
==Counter-controlled loop
This is a sum of numbers that accumulates with each iteration of a loop
==Running total
This is an item that separates other items.
==Delimiter
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
==true
If a loop does not contain within itself a way to terminate, it is called
==An infinite loop
Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?
==int number = inputFile.nextInt();*****
A loop that executes as long as a particular condition exists is called a(n) ________.
==Conditional loop
A for loop normally performs which of these steps?
==All of the above**
What will be the value of x after the following code is executed?
int x = 10;
for (int y = 5; y < 20; y +=5)
x += y;
==40
The do-while loop is a pre-test loop.
==false
The do-while loop must be terminated with a semicolon.
==true
Look at the following code:
Scanner keyboard = new Scanner(System.in);
int studentGrade = 0;
int totalOfStudentGrades = 0;
while(studentGrade != -1)
{
System.out.println("Enter student grade: :");
studentGrade = keyboard.nextInt();
totalOfStudentGrades += studentGrade;
}
In the loop header: while(studentGrade != -1), what is the purpose of "-1"
====It is a sentinel
This is a value that signals when the end of a list of values has been reached.
==Sentinel
When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.
==false
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x <= 100);
===5
What will be the values of x and y as a result of the following code?
int x = 25, y = 8;
x += y++;
==x = 33, y = 9
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
}
==This is an infinite loop
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x > 100);
==1
This type of loop is ideal in situations where the exact number of iterations is known.
==for loop
Which of the following will open a file named MyFile.txt and allow you to read data from it?
==File file = new File("MyFile.txt");
Scanner inputFile = new Scanner(file);
Subscribe to:
Posts (Atom)