Académique Documents
Professionnel Documents
Culture Documents
Response.setContentType(“text/html”); out.println(“</tr>”);
PrintWriter out = response.getWriter(); out.printIn(“<td>Cube</td>”);
Out.println (“<html>”); for (int i = 0; i <= 20; i++) {
Out.println (“<head><title>ODD Numbers</title></head>”); if ( i % 2== 1){
Out.println(“<body>”); out.printIn(“<td>” + I * I * “</td>”);
Out.println(“<table border=\”1\”>”); }
Out.println(“<tr>”); }
Out.println(“<td>Number</td>”); out.printIn(“</tr>”);
For (int i=0; I < = 20; i++ ) { out.printIn(“</body></html>”);
If ( i%2 = = 1) {
Out.println(“<td>” + I + “</td>”);
}
}
11. To display even numbers from 1 to 20 and its square root, square and cube as shown.
Number 0 2 4 6 8 10 12 14 16
Square 0 4 16 26 64 100 144 196 256
Cube 0 8 64 216 512 1000 172 2744 4096
Response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
Out.println(“<head>><title>Even, Squared and Cubed</title></head>”);
Out.println(“<body>”);
Out.println(“<table border=\”1\”>”);
Out.println(“<tr>”);
Out.println(“<td>Number</td>”); Private int computeSquare (int n) {
Out.println(“<td>Square Root</td>”); Return n*n;
Out.println(“<td>Square</td>”); }
Out.println(“<td>Cube</td>”); Private int computeCU=ube (int n) {
out.println(“</tr>”); return n*computeSquare(n);
}
for (int I = 0 ; I < = 20; I ++) { Private int computeSquareRoot (int n) {
return Math.sqet(n);
If ( i%2 = = 0) { }
Out.println(“<td>” + I + “</td>”);
Out.println(“<td>” + ComputeSquareRoot(i) + “</td>”);
Out.println(“<td>” + ComputeSquare(i) + “</td>”);
Out.println(“<td>” + ComputeCube(i) + “</td>”);
out.println(“</tr>”);
}
}
out.printIn(“</body></html>”);
}
12. Given database cars. Complete the following code in create the table models.
Database: Cars Table: models
Id (INT) Make (Varchar (255)) Model (Varchar (255)) Year (int)
1001 Ferrari 488 GTB 2016
13. Calculate the total price and discount when ordering and generate the output as shown.
Quantity Price (RM) Discount Order Received! Thank You!
1-5 2.00 0% Total: RM 12.60
6-10 1.80 10% You have ordered 7 chocolate sundaes
<html><body>
<h3> ORder Recieved! Thank you!</h3>
<%
String quantity= request.getParameter("quantity");
double total=0;
double price;
if(quantity!=null){ int q=Integer.parseInt(quantity);
if(q<5)
price=2.00;
else if(6<=q&&q<=10)
price=1.80;
else if(11<=q&&q<=20)
price=1.60;
else
price=1.20;
total=price*q;
} %>
<h3>Total:RM <%= total%></h3>
<h3> you have ordered <%=quantity%> chocolate sundaes.</h3>
</body></html>