Computer Science 109 : Introduction to
Programming
When the main method False.
parses the input parameters, Explanation: The arguments are stored as strings in the
it stores the largest numbers parameter args in the order in which they are passed in.
first.
args[0] through args[2]
When three arguments are
Explanation: Java array indexes start at 0 and there are 3
passed to the main method,
values: args[0], args[1], and args[2].
they will be stored in:
Multiple arguments separated by space.
The main method's parameter,
Explanation: Arguments are stored in a string array and can
args, allows passing which of
be converted by the main method to whatever data types
the following?
it expects.
javac
Which of the java commands
Explanation: The command javac will compile java source
will compile java files from the
files into bytecodes and the .class file(s).
command-line prompt?
Most development console/terminal command-line application
environments allow setting Explanation: Most development environments (like Eclipse
up a run configuration or IntelliJ) allow setting up a run configuration where you
where you can pre-populate can pre-populate program arguments. If program
program arguments. If arguments will change regularly, however, you can use
program arguments will the console/terminal command-line application to run the
change regularly, however, program and type in the parameters you want to pass.
you can use the____to run
the
program and type in the
parameters you want to
pass.
integer, float.
Explanation: Java will accept an
integer in a float field (would just
Based on the following code,
make it something like 25.0). But, if
what data types could be
you try to enter other data types
entered without error?
it will fail (although double may
also work, depending on the
length and precision). It's best to
check for valid values or allow
,double from the start.
, You are developing a Long.
program to accept user Explanation: The integer will not be able to hold additions of
input. Users will enter such numbers. It is best to use a long. Population counts
population counts of bacteria are whole numbers, so no need for double.
and add them together
(numbers in the billions).
Which data type would be best
for the user to convert their
input to?
It is an instance of the Scanner class.
Explanation: In order to read user
Examine the following code.
input, we need to create an instance
What is true about the
of the Scanner class to capture that
variable inputValue?
input. We will read the input into the
inputValue instance variable.
while (!enterQty.hasNextInt( ) ) {
System.out.println("Enter integer");
enterQty.next( );
Examine the following code.
}
What could we add to ensure Explanation: The exclamation
only integers were entered? point indicates an inversion/false.
In other words, while the enterQty
value is NOT an integer, display an
error. Use the next() function to
read the next value.
The Scanner utility was not
imported. Explanation: Without
This code will not compile, Java
the Scanner utility (or the entire
displays an error. What is
java.util package) you cannot
missing?
use this feature. It needs to be
imported before the first class
function.
tokens.
The Scanner class
Explanation: The Scanner class (package
(package java.util.Scanner)
java.util.Scanner) is a text scanner that breaks up input
is a text scanner that
into tokens based on a delimiter pattern such as space
breaks up input into _.
(default), semi-colon, tab, etc.
When using the Scanner class nextDouble()
to read data from the Explanation: The correct answer is 'nextDouble()' which will
console, in order to read obtain the next value and convert it to double data type
data which is a double and and return it as such.
assign it directly to a double
Programming
When the main method False.
parses the input parameters, Explanation: The arguments are stored as strings in the
it stores the largest numbers parameter args in the order in which they are passed in.
first.
args[0] through args[2]
When three arguments are
Explanation: Java array indexes start at 0 and there are 3
passed to the main method,
values: args[0], args[1], and args[2].
they will be stored in:
Multiple arguments separated by space.
The main method's parameter,
Explanation: Arguments are stored in a string array and can
args, allows passing which of
be converted by the main method to whatever data types
the following?
it expects.
javac
Which of the java commands
Explanation: The command javac will compile java source
will compile java files from the
files into bytecodes and the .class file(s).
command-line prompt?
Most development console/terminal command-line application
environments allow setting Explanation: Most development environments (like Eclipse
up a run configuration or IntelliJ) allow setting up a run configuration where you
where you can pre-populate can pre-populate program arguments. If program
program arguments. If arguments will change regularly, however, you can use
program arguments will the console/terminal command-line application to run the
change regularly, however, program and type in the parameters you want to pass.
you can use the____to run
the
program and type in the
parameters you want to
pass.
integer, float.
Explanation: Java will accept an
integer in a float field (would just
Based on the following code,
make it something like 25.0). But, if
what data types could be
you try to enter other data types
entered without error?
it will fail (although double may
also work, depending on the
length and precision). It's best to
check for valid values or allow
,double from the start.
, You are developing a Long.
program to accept user Explanation: The integer will not be able to hold additions of
input. Users will enter such numbers. It is best to use a long. Population counts
population counts of bacteria are whole numbers, so no need for double.
and add them together
(numbers in the billions).
Which data type would be best
for the user to convert their
input to?
It is an instance of the Scanner class.
Explanation: In order to read user
Examine the following code.
input, we need to create an instance
What is true about the
of the Scanner class to capture that
variable inputValue?
input. We will read the input into the
inputValue instance variable.
while (!enterQty.hasNextInt( ) ) {
System.out.println("Enter integer");
enterQty.next( );
Examine the following code.
}
What could we add to ensure Explanation: The exclamation
only integers were entered? point indicates an inversion/false.
In other words, while the enterQty
value is NOT an integer, display an
error. Use the next() function to
read the next value.
The Scanner utility was not
imported. Explanation: Without
This code will not compile, Java
the Scanner utility (or the entire
displays an error. What is
java.util package) you cannot
missing?
use this feature. It needs to be
imported before the first class
function.
tokens.
The Scanner class
Explanation: The Scanner class (package
(package java.util.Scanner)
java.util.Scanner) is a text scanner that breaks up input
is a text scanner that
into tokens based on a delimiter pattern such as space
breaks up input into _.
(default), semi-colon, tab, etc.
When using the Scanner class nextDouble()
to read data from the Explanation: The correct answer is 'nextDouble()' which will
console, in order to read obtain the next value and convert it to double data type
data which is a double and and return it as such.
assign it directly to a double