BeanShellTutorial:2 Arithmetic

From jWork.ORG
Jump to: navigation, search
Limitted access. Reguest membership or login to this link first if you are already a member


In BeanShell you also have the option of working with "loosely typed" variables. That is, you can simply omit the types of variables that you use (both primitives and objects). Now, let's try to use BeanShell as a calculator. We will calculate 3*8/6:


Numbers and Math

You can also do some calculations using elementary functions. Math functions are imported by BeanShell automatically and you will need only to call the package name Math. Let's try to use BeanShell as a calculator. We will calculate $\sqrt(100))$:


We have added the "Math" package name which is imported automatically by BeanShell. Let us consider a logarithmic function:


Default Imports

In the previous example, we called the "Math" package, which belongs to Java java.lang package. This package is imported automatically. By default, common Java core and extension packages are imported for you. They are, in the order in which they are imported:

  • javax.swing.event
  • javax.swing
  • java.awt.event
  • java.awt
  • java.util
  • java.lang


  1. Calculate logarithm of 10
  2. Calculate the absolute values of -100