Java Tutorial/JSP/Operators

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

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 int1 = 0, int2 = 0;
        out.println("int1 = " + int1 + "<BR>");
        out.println("int2 = " + int2 + "<BR>");

        int2 = int1++;
        out.println("After <B>int2 = int1++</B>:" + "<BR>");
        out.println("int1 = " + int1 + "<BR>");
        out.println("int2 = " + int2 + "<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>