Monday, 3 December 2012

Declaring Integer Variables

Integers are used to store numeric data and declared with the keyword int.There are four standard types of integers, all which can holdd both positive and negativeValues.


Simple Program Using Integers:


  1. <html>
  2. <head>
  3. <title> Simple JSP page </title>
  4. </head>
  5. <body>
  6. <h3>Using the Declaration tag declare page level variables: </h3>
  7. <p>
  8. <%!
  9. int noDays;
  10. int year=2001;
  11. int January, February, March;
  12. %>
  13. <p>
  14. <b>Notes:</b>The Declaration tag does not produce any output.
  15. <p>
  16. <%
  17. noDays=365;
  18. %>
  19. The Number of days in a year is <%=noDays%>
  20. </body>
  21. </html>

Description:

  • Type <%! to open the Declaration tag.
  • Type int followed by the variable name and a semicolon.ths declares a single variable as an integer.(int noDays;)
  • Use the equal sign(=) to assign a value to the variable when it is being initialized.This is known as explicit initialization.(int year=2001;)
  • You can initialize more than one variable of same type by separating each variable name with a comma.(int January, February, March;)
  • Type %>  to close the Declaration tag.
  • Type = sign to assign a value to a variable.The value must be placed on the right side of the equal sign.(noDays=365;)
  • Use the expression tag to print the value of a variable.(<%=noDays%>)


*************************OUTPUT*****************************************

Using the Declaration tag declare page level variables:

Notes:The Declaration tag does not produce any output.
The Number of days in a year is 365

************************************************************************** 








2 comments: