Computer Science › Console Output
Consider the following code:
for(int i = 1; i <= 10; i++) {
for(int j = 0; j < (20 - i * 2) / 2; j++) {
System.out.print(" ");
}
for(int j = 0; j < i * 2; j++) {
System.out.print("*");
}
for(int j = 0; j < (20 - i * 2) / 2; j++) {
System.out.print(" ");
}
System.out.println();
}
Describe the output of the code above.
Given:
int\[\]\[\] myArray = { {1, 2},
{3, 4} };
What would the following statement print out to the console?
System.out.print(myArray\[1\]\[1\] + 10);
Does the code compile and if yes, what is the the output?
public class Test
{
public static void main ( String \[\] args )
{
int x = 2;
if (x = 2)
System.out.println("Good job.");
else
System.out.println("Bad job);
}
}
True or False.
The output of this code snippet will be "Hello, I'm hungry!"
public static void meHungry() {
String hungry = "hungry";
String iAm = "I'm";
String hello = "Hello";
String message = "";
if (hungry != null) {
message += hungry;
}
if (hello != null && iAm != null) {
message = hello + iAm + hungry;
}
System.out.println(message);
}
Consider the following code:
What is the output of the method call mystery("Green eggs and ham")
Which of the following blocks of code will output an evenly-spaced 2D array (i.e. an evenly-spaced matrix)? For example, a simple evenly-spaced matrix is:
1 2 3
4 5 6
7 8 9
int a = 10, b = 5;
for(int i = 0; i < a; i+=2) {
for(int j = 0; j < i % b; j++) {
System.out.print("* ");
}
System.out.println();
}
What will be the console output for the code above?
In Swift (iOS), give a description of what this method does.
func getDivisors(num: Int, divisor: Int) -> Bool {
var result: Bool = False
if (num % divisor == 0) {
result = True
}
println(result)
}
What is the output of this program?
arr = \["hello", "my", "name", "is"\]
for (int i = 0; i < arr.length - 1; i++) {
System.out.println(arr\[i\]);
}
System.out.println("Sandra");
What will the following code result in?
int main(){
int i = 7;
const int * ip = &i;
cout<< *ip << endl;
}