About Me

header ads

Variables In Progamming
variable is a special type of amount or quantity with an unknown value.It is data storage location.Is a identifier that define storage location use to store a value as a data , not like a constant variable , it may take different values in different time during the program execution.



Variable Types -
    • String    - stores text, such as "Hello". String values are surrounded by double quotes
    • Int          - stores integers (whole numbers), without decimals, such as 123 or -123
    • Float      - stores floating point numbers, with decimals, such as 19.99 or -19.99
    • Char      - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
    • Boolean - stores values with two states: true or false


Features of Variables -

1.It Should be meaningful name and must have Constant ( Unique ) name .
        Ex - myNum
               firstName

2.Variable name consists Alphabet , Digit , Underscore ( _ ) , or Dollar Sign ( $ ).
        Ex - myNum
               $firstName

3.It not begin with a Digit.
       Ex - 1st november   ( Wrong )
               2 days  ( Wrong )

4.Spaces not allow between two characters ( Words ). 
       Ex - Full Name   ( Wrong )

               Fullname  ( Right )

5.Uppercase , Lowercase different.
       Ex - FullName   
              Fullname  
              FULLNAME 

6.Length should between less than 255 Bits. ( 15 Characters )

7.Name should not be a keyword.
Keywords -


Variable Examples in Java -


int myNum;
myNum = 15;
System.out.println(myNum);
* myNum is the Variable.
String firstName = "John ";
String lastName = "Doe";
String fullName = firstName + lastName;
System.out.println(fullName);
firstName , lastName are the Variables.


Variable Examples in Scrach -

1.Create a Variables in Scrach


2.Simple Codes With Variables -




Post a Comment

0 Comments