2. Variables
Variables are analogous to Buckets or Envelopes where
information can be stored.
We call buckets by names so Variables must have
names for calling.
Information stored in Variables can also be changed.
Name of the variable is anything your name also.
3. Data Types
Data types tell about what type of value our variable
want to store
It may be INT FLOAT DOUBLE CHAR STRING
Int:-It will take only integer value no value after
decimal point
Float:-It will take values after decimal point but has
less precison also known as floating point.
Double:-Also called floating point because decimal
points flaot more precise than float
4. Data Types Continued
Char:-It only takes a character it is one byte only takes
only character
For examples
Int =10
Float=10.232
Double=10.32322
Char =‘d’
Char =‘+’
5. Assignment Operator
Assignment operator “=“ is used to assign value to a
variable
Beware not used this “==“ be cause it is equality
operator it checks the equality between variable name
and value assigned to it.
Syntax will be
Data type variable name assignment operator value
6. Variable Names
It is up to you what name you give to your variables
For examples
Int number=10;
First DATA TYPE is INT as it only accept integer which is 10
Second name of our variable is NUMBER name could be
anything here I used Number you can use your name also
Third Assignment operator we give our variable Number a
value so after this
Number=10 our variable number can store an integer
number 10.
7. Some Examples
Int number=10;
Int bob=20;
Int khan=30;
Float num=10.87;
Float numbe=10.8;
Double num1=10.2321;
Double khan=10.43434;
8. Some Examples
Char name=‘c’;
Char ali=‘d’;
Char sign=‘+’;
Char bob=‘-’
Char mult=‘*’;
Note(we will discuss strings later it is also a data type i
will create full slides on strings)
9. Key Points For Char
Char variable can be of 1 byte means it contain only
only character
Char name=‘d’; TRUE
Char name=‘d+’ FALSE
Char sign=‘++’ FALSE
Char sign=‘+’ True
Always use this ‘’ for values
10. Comments
Always use comments it is good programming pratice
The benefit of commenting is that some one who sees
your code can easily understand it
For comments use
//this is my prog//
Compiler can execute your programme line by line and
ignore the comments line it does not effect your
programme performance
Use //I am a commnet//
11. Simple Example
In C++ In Java
#include<iostream>
using namespace std;
int main()
{
int
number=10,number1=20,add;//i
nitialize variable and assign
values//
add=number+number1;//result
of these will be stored in add//
cout<<add;//for displaying//
}
Thanks to Devc++
public class JavaApplication6 {
/**
* @param args the command line
arguments
*/
public static void main(String[]
args) {
int number=10,number1=20,add;
add=number+number1;
System.out.println(add);
}
}
Thanks to netbeans