Computer Science › Standard Data Structures
Which of the following blocks of code converts an array of characters into a string?
boolean x;
int y;
x = false;
y = 10;
x = !(y < 10 || y > 10);
System.out.println ( x );
What is printed?
Which of the following blocks of code converts an array of characters into a string?
Consider the following code:
int\[\] a = {8,4,1,5,1,5,6,2,4};
int b = 1;
boolean\[\] vals = new boolean\[a.length\];
for(int i = 0; i < a.length; i++) {
vals\[i\] = (a\[i\] - 1 > 4);
}
for(int i = 0; i < vals.length; i++) {
String s = "Duns Scotus";
if(!vals\[i\]) {
s = "Mithrandir";
}
System.out.println(s);
}
What is the output for the code above?
boolean x;
int y;
x = false;
y = 10;
x = !(y < 10 || y > 10);
System.out.println ( x );
What is printed?
Consider the following code:
public static void main(String\[\] args) {
double\[\]\[\] matrix = {{1,6,7},{1,4,5}};
graphics(matrix);
}
private static double graphics(double\[\]\[\] x) {
double r = 0;
for(int i = 0; i < x.length; i++) {
for(int j = 0; j < x\[i\].length; j++) {
r += x\[i\]\[j\] * (i + 1);
}
}
return r;
}
What is the return value for graphics in the code below:
double\[\]\[\] matrix = {{1,6,7},{1,4,5}};
graphics(matrix);
Consider the following code:
int\[\] a = {8,4,1,5,1,5,6,2,4};
int b = 1;
boolean\[\] vals = new boolean\[a.length\];
for(int i = 0; i < a.length; i++) {
vals\[i\] = (a\[i\] - 1 > 4);
}
for(int i = 0; i < vals.length; i++) {
String s = "Duns Scotus";
if(!vals\[i\]) {
s = "Mithrandir";
}
System.out.println(s);
}
What is the output for the code above?
Which is true?
a = 4
b = 2
c = 5
d = 6
a) a = c - d
b) a = b - d
c) a = d - b
d) a = c * d
Which of the following Boolean expression evalutes to True?
I. False && False && False && True && False
II. (False && False) || (True || False) || (False && (True || False))
III. (True && False) && (True || False || (True && True))
IV. !(True && True && False)
V. False || False || False || True || False
Consider the following code:
public static void main(String\[\] args) {
int\[\] vec = {8,-2,4,5,-8};
foo(vec);
}
private static void foo(int\[\] x) {
for(int i = 0; i < x.length; i++) {
int y = Math.abs(x\[i\]);
for(int j = 0; j < y; j++) {
System.out.print(x\[i\] + " ");
}
System.out.println();
}
}
Which of the following represents a possible output for the program above?