0% found this document useful (0 votes)
2 views3 pages

Java Level 1 Exam Questions

The document presents 11 questions from a Level 1 Java exam. The questions cover topics such as conditional expressions, for loops, algorithms, inheritance, code output, data types, assignments, classes, and methods. It asks to determine results, correct errors, and explain concepts related to the Java language.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Java Level 1 Exam Questions

The document presents 11 questions from a Level 1 Java exam. The questions cover topics such as conditional expressions, for loops, algorithms, inheritance, code output, data types, assignments, classes, and methods. It asks to determine results, correct errors, and explain concepts related to the Java language.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Exam - Java Level 1

Gilbert Encarnacion Castillo


.

1. Indicate what the result of the expression in bold would be considering the value
from the variables a, b, c, d, and e that appear below:
int a = 3; int b
=5; int c = 4;
boolean d =
false; boolean e
= false;
(a+b-c < c ) || (d || e)

a) true
b) false.
c) 4

2. Indicate the number of times the following loop would be executed:

for(int i=10; i>5; i=i+2)


{ [Link]("H
hello

a) None because it never takes the value <= 5.


b) Two (for i=5, 7)
c) Infinite because it never takes on a value <= 5

3. An algorithm is:

a) A series of organized steps that describe the process to follow to solve a problem
specific
b) A set of rules that can be applied in each of the states of a problem to
moving towards the solution
c) The sequence of instructions to optimally solve a problem

4. Indicate whether the following statements are true, and briefly explain why.
a) "It is possible for objects belonging to the same class to have attributes that have the same
value for all and that they change in all when one changes.
b) "Inheriting from a class that in turn inherits from another is considered multiple inheritance and is
forbidden in Java. (Example: class A inherits from B and class B inherits from C)
5. Given the following Java code:
public void method1(int number) {

for(int i = 0; i < number; i++){


for(int j = 0; j <= i; j++){
[Link](i + j);
if(((i + j) % 2) == 0)
**
else
--
}

[Link]();
}
}

What would be the output to the screen after executing method1(3)?

6. Execute the following loop step by step: c = 5;


for (a=1; a<5; a++) c
= c - 1;
What value do a and c end with?

7. Indicate whether the assignment that appears in the following Java code is correct or not and correct it.
in case it is not. Indicate what the value stored in the variable d would be as a result of
the assignment:

double d; int i=2; char c='a'; d = i


+ c; // Is the assignment correct?

8. Proceed in the same way for the following code, indicating what value would be stored in the
variable i:

double d=3.72; int i; int j=10; i = j + d


+ '"';// Is the assignment correct?

9. The assignment that appears below is incorrect. Indicate how to correct it so that the
the value stored in i should be as close as possible to the mathematical result of the expression (d*j =
37.2). Indicate what the value stored in i would be.
double d=3.72; int i; int j=10; i
= d * j;// incorrect assignment

10. Given the following Java class:

public class Question4 { public static void


main(String[] args) { byte[] values = new
byte[] {1, 2, 3}; int tmp = 5; tmp *=
method(1);
[Link]("Temporal value: " + tmp);
int tmp2 = [Link] + values[1];
[Link]("Second time value:" + tmp2); int
tmp3 = tmp2 % 4;
Third temporary value:
}

private static int method(int variable) {


[Link]("Method with value:" + (++variable)); return
variable;
}
}

Explain what the output would be when executing the Question class

11. Create a traffic light where it starts at Red for 3 minutes, then Yellow for 1 minute, and continue to the
Green for 4m and then return to Red. The traffic light must always be active. Implement this algorithm in
any language or pseudocode.

You might also like