This code: final double d = 1 / 2; System.out.println(d); prints 0. Why? How do you make this code print 0.5 instead?
The problem here is that this expression: 1 / 2 has integer literals on both sides of the operator: 1 and 2. As a consequence, an integer division will be performed, and the result of 1 divided by 2 of an integer division is 0. In order for the result to be a double as expected, at least one operand of the operation needs to be a double. For instance: final double d = 1 / 2.0; or: final double d = 1.0 / 2;
3) Write an HTML table tag sequence that outputs the following: 50 pcs 100 500 10 pcs 5 50
<table> <tr> <td>50 pcs</td> <td>100</td> <td>500</td> </tr> <tr> <td>10 pcs</td> <td>5</td> <td>50</td> </tr> </table>
What is wrong with the SQL query below? SELECT UserId, AVG(Total) AS AvgOrderTotal FROM Invoices HAVING COUNT(OrderId) >= 1
The issue here is that there must be a GROUP BY clause here. This query will get the average order amount by the customer (UserId) where the customer has at least 1 order. The correct query is listed below: SELECT UserId, AVG(Total) AS AvgOrderTotal FROM Invoices GROUP BY Userid HAVING COUNT(OrderId) >= 1