Programming 1- CS1102 – UoPeople. 2022/2023. 100% Approved pass rate. Graded A+
The operation ++ in Java means:
Select one:
a. That the value of 1 is added to the variable
b. That the program should start execut
...
Programming 1- CS1102 – UoPeople. 2022/2023. 100% Approved pass rate. Graded A+
The operation ++ in Java means:
Select one:
a. That the value of 1 is added to the variable
b. That the program should start executing from the beginning
c. That this line is a comment
d. That the value should be raised to the power of 2 - ☑☑a. That the value of 1 is added to the variable
The rules that determine what is allowed in a program are known as the ____ of the language.
Select one:
a. syntax
b. grammar
c. semantics
d. pragmatics - ☑☑a. syntax
Variables of the type short can have values in the range of:
Select one:
a. integers between -128 and 127 inclusive
b. integers in the range -32768 and 32767
c. integers in the range -2147483648 and 2147483647
d. integers in the range -1024 and 1024 - ☑☑b. integers in the range -32768 and 32767
The size of a variable of type double is:
Select one:
a. 8 bytes
b. 4 bytes
c. 2 bytes
d. 16 bytes - ☑☑a. 8 bytes
A language that generates a syntax error when you try to put a different data type into a variable that it has not be declared for is called a ________ language. - ☑☑strongly typed
Which of the following is an object type?
Select one:
a. byte
b. boolean
c. char
d. String - ☑☑String
What output will the following code produce:
int x, y;
boolean sameSign;
x=1;
y=1;
sameSign = ((x>0)==(y>0));
System.out.println(sameSign);
Select one:
a. true
b. 1
c. 0
d. false - ☑☑True
A memory location that has been given a name is called a: - ☑☑variable
Which of the following is NOT a primitive data type.
Select one:
a. short
b. byte
c. double
d. String - ☑☑String
In Java, a variable of type long is ___ bytes in size. - ☑☑8 bytes (64 bits)
A variable of type 'float' is represented in ___ bytes: - ☑☑4 bytes (32 bits) Correct
In java, a variable can only be used in a program if it has first been: - ☑☑Declared
Subroutines in Java are often referred to as: - ☑☑Methods
What output will the following code produce:
int counter;
counter = 5;
counter += 1;
System.out.println(counter); - ☑☑6
What output would the following code produce?
enum Season { SPRING, SUMMER, FALL, WINTER } ;
Season vacation;
vacation = Season.SUMMER;
System.out.println(Season.SUMMER); - ☑☑SUMMER
A statement with the following format
variable1 = ( x>=2) ? x++ : x--;
is employing a:
Select one:
a. conditional operator
b. boolean logic
c. type cast
d. relational operator - ☑☑Conditional operator
True or False: The fetch and execute cycles always alternate? - ☑☑True
True or False: A computer is built to carry out instructions that are written in a simple type of language called binary language. - ☑☑True
True or False: A variable has a value that can not be changed by the program. - ☑☑False
True or False: The word "public" when placed in front of a method declaration in java means that the routine can only be called from within the local class. - ☑☑False
True or False: A variable of type boolean in java can have precisely two literals. - ☑☑True
True or False: An asynchronous event is one that occurs at an unpredictable time outside the control of the program that the CPU is running. - ☑☑True
True or False: Java programs are NOT compiled. - ☑☑False
True or False: One of the components of a computer is its CPU, which converts the Input to the Output - ☑☑False
True or False: A name for a constant value in java is called a literal. - ☑☑False
True or False: An enum (enumerated type) is a example of an object type instead of a primitive type? - ☑☑True
Which of the following statements about the 'block' statement are true - ☑☑it groups a sequence of statements into a single statement
What output will the following code produce:
int number;
number = 1;
while ( number < 6) {
System.out.print(number);
number += 1;
} - ☑☑12345
What is the following java code structure known as:
for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
// do something
}
} - ☑☑Nested loop
Which statement is most value regarding the following java code:
while ( true ) {
System.out.print("loop again");
} - ☑☑it is a infinite loop that will continue to loop forever (until the program is terminated)
What will the following java code produce as output?
int number;
number = 1;
while ( number < 6 ) {
System.out.print(number);
number = number + 1;
}
System.out.print("Done!"); - ☑☑12345Done!
What will the following java code do if stringFunction is called as follows:
String x = stringFunction("mississippi");
static String stringFunction(String str) {
String test;
int i;
test = "";
for (i = str.length() - 1; i >= 0; i--) {
test = test + str.charAt(i);
}
return (test);
} - ☑☑ippississim
An "animation" consists of a sequence of images shown rapidly one after the other on the computer screen. Each image in the animation is called a "frame." Suppose that you have a subroutine
static void showFrame(int frameNum)
that displays one frame in an animation. That is, showFrame(1) displays the first frame, showFrame(2) displays the second frame, and so on. Suppose that there are a total of thirty different frames.
How many frames will the following code display?:
for (int play = 0; play < 10; play++) {
for (int i = 1; i < =30; i++)
showFrame(i);
} - ☑☑30 frames repeated 10 times
True or False: A for loop can use a list structure such as an enum to iterate the for loop? - ☑☑True
True or False: The break loop when encountered will cause processing to skip to the beginning of the loop? - ☑☑False
True or False: The continue statement when used in a loop will cause the flow of process to skip to the end of the loop and begin another iteration of processing? - ☑☑True
True or False: A for loop is used when the number of iterations through the loop is known in advance? - ☑☑True
True or False: The while loop is used when a known, finite number of loop iterations is required. - ☑☑False
True or False: The conditional expression in a while loop can be any expression that evaluates to a logical True or False? - ☑☑True
True or False: The while loop repeats a set of code while the condition is false. - ☑☑False
True or False: The for loop repeats a set of statements a certain number of times until a condition is matched. - ☑☑True
True or False: Can a for statement loop indefinitely? - ☑☑True
True or False: The do-while loop repeats a set of code at least once before the condition is tested. - ☑☑True
Suppose that the first line of a subroutine definition is: static void test(int n, double x).
Now consider these statements:
test(17,42)
test(0.17,3.227)
Which of those statements is a legal subroutine call? - ☑☑test(17,42)
A program contains a switch statement that lets you test the value of an expression and, depending on that value, to jump directly to some location within the switch statement.
When compiling the program, when will a Java compiler report an error?
a. If the value of the expression is a char, or a short.
b. If the value of the expression is a String or a real number.
c. If the value of the expression is an int or byte.
d. If the value of the expression is an enum. - ☑☑b. If the value of the expression is a String or a real number.
A "black box" has an interface and an implementation.
Which of the following statements describe interface? - ☑☑The interface of a black box is its connection with the rest of the world, such as the name and parameters of a subroutine.
What are formal parameters ? - ☑☑Formal parameters are found in the subroutine definition. The values of the actual parameters are assigned to the formal parameters before the body of the subroutine is executed.
Here is the definition of the Pythagoras function:
static double Pythagoras (double x, double y) {
// Computes the length of the hypotenuse of a right
// triangle, where the sides of the triangle are x and y.
return Math.sqrt( x*x + y*y );
}
[Show More]