STEM / NEWEST ACTUAL EXAM QUESTIONS BANK /
COMPLETE ACCURATE QUIZZES WITH DETAILED VERIFIED
ANSWERS / 2025
What return statement may be return new String[] {"apple", "banana", "orange"};
used in the method s()?
This is correct because this is the proper way to call a String array and it
public static String[] s() is what the method is asking for.
{
// ...
} public static void main(String[]
args)
{
String[] words = s();
// ...
}
What does the following method Returns the sum of all elements other than x in the array.
do?
This is correct because s only adds in a[i] if a[i] does not equal x.
public static int mystery(double[]
a,double x)
{ int s = 0; for (int i = 0; i <
a.length; i++)
{ if (a[i] !=
x)
{ s = s + a[i]
;
}
} return
s;
}
Terms in this set (20)
, Consider the following instance for (int x : nums)
variable and method. { if (x % 3 ==
0)
private int[] nums; {
/* print the elements in nums which System.out.println(x);
are a multiple of three / public void }
printMultiplesOfThree() }
{
/ missing code / This is correct as we are looking to see if the element inside nums is a
} multiple of 3.
Which of the following
replacements for / missing code
/ correctly implements the method
printMultiplesOfThree()?
Assume the following method has 4
been defined:
This is correct because only 4 of the values have a length that is less or
public static int mystery(String[] a, equal to 4.
int x)
{ int c = 0; for (int i = 0; i <
a.length; i++)
{ if (a[i].length() <=
x)
{ c+
+;
}
} return
c; }
What is output by the following
code?
String[] b = {"rain", "beach", "any",
"love", "emotion", "sunny", "go"};
System.out.println(mystery(b, 4));
If you want to use an array as a data type of the array
parameter in a method, in the
method declaration, you must first
This is correct as you must identify what type the array is first before
include ________.
putting in an array as an argument.