Java/JSP/Operator
Содержание
Adding value
<%--
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 session="false" %>
<%
int value = 3;
%>
<p>The value is <%= value %></p>
<%
value += 2;
%>
<p>After adding 2, the value is <%= value %></p>
Addition and Subtraction
<HTML>
<HEAD>
<TITLE>Addition and Subtraction</TITLE>
</HEAD>
<BODY>
<H1>Addition and Subtraction</H1>
<%
int operand1 = 15, operand2 = 24, sum, difference;
sum = operand1 + operand2;
difference = operand1 - operand2;
out.println(operand1 + " + " + operand2 + " = " + sum + "<BR>");
out.println(operand1 + " - " + operand2 + " = " + difference);
%>
</BODY>
</HTML>
Checking Operator Precedence
<HTML>
<HEAD>
<TITLE>Checking Operator Precedence</TITLE>
</HEAD>
<BODY>
<H1>Checking Operator Precedence</H1>
<%
double value;
value = (10 + 24) / 2;
out.println("The value = " + value);
%>
</BODY>
</HTML>
Incrementing and Decrementing
<HTML>
<HEAD>
<TITLE>Incrementing and Decrementing</TITLE>
</HEAD>
<BODY>
<H1>Incrementing and Decrementing</H1>
<%
int value1 = 0, value2 = 0;
out.println("value1 = " + value1 + "<BR>");
out.println("value2 = " + value2 + "<BR>");
value2 = value1++;
out.println("After <B>value2 = value1++</B>:" + "<BR>");
out.println("value1 = " + value1 + "<BR>");
out.println("value2 = " + value2 + "<BR>");
int value3 = 0, value4 = 0;
out.println("<BR>");
out.println("value3 = " + value3 + "<BR>");
out.println("value4 = " + value4 + "<BR>");
value4 = ++value3;
out.println("After <B>value4 = ++value3</B>:" + "<BR>");
out.println("value3 = " + value3 + "<BR>");
out.println("value4 = " + value4 + "<BR>");
%>
</BODY>
</HTML>
Multiplication and Division
<HTML>
<HEAD>
<TITLE>Multiplication and Division</TITLE>
</HEAD>
<BODY>
<H1>Multiplication and Division</H1>
<%
double double1 = 6, double2 = 8, double3 = 5, doubleResult;
doubleResult = double1 * double2 / double3;
out.println("6 * 8 / 5 = " + doubleResult);
%>
</BODY>
</HTML>
Using Logical Operators
<HTML>
<HEAD>
<TITLE>Using Logical Operators</TITLE>
</HEAD>
<BODY>
<H1>Using Logical Operators</H1>
<%
int temperature = 70;
if (temperature < 90 && temperature > 60) {
out.println("Picnic time!");
}
%>
</BODY>
</HTML>
Using Operators
<HTML>
<HEAD>
<TITLE>Using Operators</TITLE>
</HEAD>
<BODY>
<H1>Using Operators</H1>
<%
int operand1 = 23, operand2 = 4, product;
product = operand1 * operand2;
out.println(operand1 + " * " + operand2 +
" = " + product);
%>
</BODY>
</HTML>
Using Relational Operators
<HTML>
<HEAD>
<TITLE>Using Relational Operators</TITLE>
</HEAD>
<BODY>
<H1>Using Relational Operators</H1>
<%
int temperature = 70;
if (temperature < 80) {
out.println("Just right.");
}
%>
</BODY>
</HTML>