Java/JSP/Data Type

Материал из Java эксперт
Версия от 07:10, 1 июня 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

An Automatic Data Conversion

<HTML>
  <HEAD>
    <TITLE>An Automatic Data Conversion</TITLE>
  </HEAD>
  <BODY>
    <H1>An Automatic Data Conversion</H1>
    <%
        double double1;
        float float1 = 1;
        double1 = float1;
        out.println("double1 = " + float1);
     %>
  </BODY>
</HTML>





Casting to a New Type

<HTML>
  <HEAD>
    <TITLE>Casting to a New Type</TITLE>
  </HEAD>
  <BODY>
    <H1>Casting to a New Type</H1>
    <%
        float float1;
        double double1 = 1;
        float1 = (float) double1;
        out.println("float1 = " + float1);
     %>
  </BODY>
</HTML>





double: Finding Average Grades

<HTML>
  <HEAD>
    <TITLE>Finding Average Grades</TITLE>
  </HEAD>
  <BODY>
    <H1>Finding Average Grades</H1>
    <%
        double grades[] = {88, 98, 73, 56, 86, 64};
        double sum, average;
        sum = 0;
        for (int i = 0; i < grades.length; i++) {
            sum += grades[i];
        }
        average = sum / grades.length;
        out.println("Average grade = " + average);
    %>
  </BODY>
</HTML>





Scriptlet Example

<%--
  Copyright (c) 2002 by Phil Hanna
  All rights reserved.
  
  You may study, use, modify, and distribute this
  software for any purpose provided that this
  copyright notice appears in all copies.
  
  This software is provided without warranty
  either expressed or implied.
--%>
<%@ page import="java.text.*" session="false"%>
<html>
<head>
<title>Scriptlet Example</title>
</head>
<body>
<table border="0" cellpadding="3">
<tr>
   <th>Fahrenheit</th>
   <th>Celsius</th>
</tr>
<%
   NumberFormat fmt = new DecimalFormat("###.000");
   for (int f = 32; f <= 212; f += 20) {
      double c = ((f - 32) * 5) / 9.0;
      String cs = fmt.format(c);
%>
   <tr>
      <td align="RIGHT"><%= f %></td>
      <td align="RIGHT"><%= cs %></td>
   </tr>
<%
   }
%>
</table>
</body>
</html>