Friday 21 October 2016

Why variables

Why should we learn java variables

  • In my childhood sometimes my mum used to ask additive operations,
Example
                5  + 6   = ?
              6  - 5.5 = ?
              6  * 5   = ?
  • Hope everyone knows the answer key for above question paper.
  • OK be cool, in the same way if you want to ask above questions to Java programming language then you have to learn Variables topic, which makes you clear what data is assigned to which variable.
  • Even below program gives the result without variables concept but according to java we need to assign every value to a variable to do specific a operation.
------------------------------------------------------------------------------------------------

Program         :       Program on basic variables
Program name  :       MumQuestions.java
Output            :         
                              Addition of 5 and 6 :11
                              Subtraction of 6 and 5.5 : 1.5
                              Multiplication of 6 and 5 : 30
class MumQuestions
{
        public static void main(String args[])
        {
                System.out.println(“Addition of 5 and 6 : ”+(5+6));
                System.out.println(“Subtraction 5 from 6 : ”+(6-5));
                System.out.println(“Multiplication of 6 with 5 : ”+(6*5));
        }
}

Compile     :      javac MumQuestions.java
Run           :      java MumQuestions
Output       :         
                       Addition of 5 and 6 :11
                       Subtraction 5 from 6 : 1
                       Multiplication of 6 with 5 : 30

------------------------------------------------------------------------------------------------
   Thanks for your time.
   Nireekshan