Java/JSP/Data Type

Материал из Java эксперт
Перейти к: навигация, поиск

An Automatic Data Conversion

   <source lang="java">

<HTML>

 <HEAD>
   <TITLE>An Automatic Data Conversion</TITLE>
 </HEAD>
 <BODY>

An Automatic Data Conversion

   <%
       double double1;
       float float1 = 1;
       double1 = float1;
       out.println("double1 = " + float1);
    %>
 </BODY>

</HTML>


      </source>
   
  
 
  



Casting to a New Type

   <source lang="java">

<HTML>

 <HEAD>
   <TITLE>Casting to a New Type</TITLE>
 </HEAD>
 <BODY>

Casting to a New Type

   <%
       float float1;
       double double1 = 1;
       float1 = (float) double1;
       out.println("float1 = " + float1);
    %>
 </BODY>

</HTML>

      </source>
   
  
 
  



double: Finding Average Grades

   <source lang="java">

<HTML>

 <HEAD>
   <TITLE>Finding Average Grades</TITLE>
 </HEAD>
 <BODY>

Finding Average Grades

   <%
       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>

      </source>
   
  
 
  



Scriptlet Example

   <source lang="java">

<%--

 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>

<% 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); %> <% } %>
Fahrenheit Celsius
<%= f %> <%= cs %>

</body> </html>


      </source>