SOLUTION
SOLUTION
Question 1
1. False
2. False
3. True
4.True
5.False
Question 2
1. D
2. C
3. A
4. D
5. D
6. A
7. C
8. C
9. B
10. A
Question 3
This program display the following on the screen:
c=b
c=c
c=d
c is not a, b, c, or d
s0 doesn 't say hello world ...
0, 3, 6, 9, 12, 15, 18, 21, 24, 27,
1
The application Test 1 declares one local variable c of type char initialized with the value
'b', and one local variable s0 of type String initialized to " Hello World ".
The switch case that follows the variable declaration will take as expression the value of variable
c. The value of c is matched with each switch case till a match is found. The value of c is 'b' for
that reason the code that is specified in the case 'b': will be executed. The instruction in this case
and other cases in this switch are not ended by break statement. Therefore, the instructions in the
other cases that are after the matched case (case 'b':) until the end of the switch including default
case will be executed.
s0. toLowerCase (); statement will return a string that has the letters of string that s0 refers
converted to small letters (" hello world "). But this method will not change s0.
Therefore the condition of if statement will be evaluated to false and else branch will be executed.
for statement will create the loop that runs 30 times having a counter i initialized to 0, incrementing
i by one in each step until the condition i<30 is fulfilled. Inside the body for there is one statement
if that will test if i is divisible by 3 or not. If it is divisible it will print the value of i followed by
‘,’
Since i is in a range from 0 to 29 the following numbers will be printed when for statement is
executed:
0, 3, 6, 9, 12, 15, 18, 21, 24, 27,
Question 4
import java.util.Scanner;
public class Test1
{ static void pairs_value(int inputArray[], int inputNumber) {
System.out.println("Pairs of elements and their sum : ");
// Iterate through the elements of the inputArray.
for (int i = 0; i < inputArray.length; i++) {
// Iterate through the elements following the current i.
for (int j = i + 1; j < inputArray.length; j++) {
// Check if the sum of inputArray[i] and inputArray[j] equals the inputNumber.
if (inputArray[i] + inputArray[j] == inputNumber) {
// Print the pair of elements and their sum.
2
System.out.println(inputArray[i] + " + " + inputArray[j] + " = " +
inputNumber);
}
}
}
}
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.println("Give the specific number");
int nr=scan.nextInt();
System.out.println("Give the capacity of array number");
int n=scan.nextInt();
int[] arr=new int[n];
for (int i=0; i<n; i++)
{
System.out.println("Give the elemnt " + (i+1) + " of array ");
arr[i]=scan.nextInt();
}
// Call the pairs_value method with an array and specific number.
pairs_value(arr, nr);
}
}
Question 5
public class Employee {
private String emp_id;
private String emp_name;
private int emp_salary;
public Employee() {
3
this.emp_id= 0;
this.emp_name= “”;
this.emp_salary=0;
}