Java and SQL Exam Questions Guide
Java and SQL Exam Questions Guide
The statement that the value remains unchanged is FALSE. In Java, when a high-precision data type is assigned to a low-precision data type via forced conversion, there can be a loss of precision and the actual value may change .
The break statement will terminate the loop when i equals 3, therefore the output of the program is '012'. The loop starts from 0 and continues until i is less than 10, but breaks at 3, printing numbers 0, 1, and 2 .
The expressions (x > 0 || x < 10 && y < 0) and ((x > 0 || x < 10) && y < 0) will have different values due to operator precedence. The former evaluates 'x < 10 && y < 0' first and then 'x > 0', whereas the latter gives precedence to 'x > 0 || x < 10' due to the parentheses, and then evaluates 'y < 0', so they may evaluate to different results .
To create a 'Student' table in SQL, you can use the following statement: CREATE TABLE Student (Studentid VARCHAR(10) PRIMARY KEY, Name VARCHAR(10), Sex VARCHAR(2)).
The correct syntax for throwing a ServiceException is using 'throw new ServiceException()' .
A nested loop program can be designed using two loops, where the outer loop runs through numbers 1 to 100, and the inner loop calculates the sum by adding each number iteratively: for (int i = 1; i <= 100; i++) { sum += i; System.out.println("Sum up to " + i + " = " + sum); } .
To delete the course where the teacher is 'Justin Br', the SQL query is: DELETE FROM course WHERE Teacher = 'Justin Br' .
The correct answer is D. String, as it is not a primitive data type in Java. In Java, the underlying or primitive data types include boolean, char, double, among others .
To update the score for 'Michael Jordan' to 90 in the computer subject, the SQL statement is: UPDATE sc SET Grade = 90 WHERE Studentid = (SELECT Studentid FROM student WHERE Name = 'Michael Jordan') AND CourseID = (SELECT CourseID FROM course WHERE CourseName = 'Computer')
To query students who take at least one course but not all, you can use: SELECT Studentid, Name, Sex, COUNT(CourseID) as Courses_Taken FROM student JOIN sc USING (Studentid) GROUP BY Studentid HAVING COUNT(CourseID) < (SELECT COUNT(*) FROM course)