Easy practice with java variables
Java programming
Nooria Esmaelzade
2016
Which one keeps the water?? Which one is
preferred??
(A)
(B)
(C)
(D)
Of course this one!!
The dish keeps the water or
water keeps the dish???
Of course the dish keeps the
water
To keep the data, we need something like a
dish in java
Variables can help us here
They act like the dish
We must define the type of every variable/ dish that holds the data
Analyze it, which one is the water and which one is
the dish and which one is the type of the dish??
int x = 10 ;
int 10 = x ;
So is it right or wrong??
Data type
Variable/ dish Data
Primitive data types
integral (‫)صحیح‬ floating point(‫)اعشاری‬ Boolean
Byte short int long
8-bit 16-bit 32-bit 64-bit
Float double
32-bit 64-bit
True false
Compute the circle area
formula (𝑎𝑟𝑒𝑎 = 𝜋𝑟2)
1- data holders (variables, constant)
2- assign value and calculate the area
3- display the result
circle area
public class CircleArea {
public static void main(String[] args) {
// Declare and initialize the variables
double r=10;
final double PI= 3.1415;
// calculate the circle area
double area = PI*r*r;
// display the result
System.out.print("This is the area of circle: "+area +" u263A");
}
}
Practice in the class
Get area of a square
Formula( area = 𝑎2
)
public class Squarearea {
public static void main(String[] args) {
//Declare variables
double a;
double area;
// Assign value
a=3;
// get the square area
area=a*a;
// display the result
System.out.println("The area of Square with length " +a+ " is: "+ area);
}
}
Assignment
Compute the area of Triangle A =
hbb
𝟐
Compute the rectangle area A= width* length
Rectangle area
public class Rectangle {
public static void main(String[] args) {
int l = 20;
int w =10;
int area = l * w;
System.out.println("The area of rectangle is: "+ area);
}
}

Easy practice with java variables

  • 1.
    Easy practice withjava variables Java programming Nooria Esmaelzade 2016
  • 2.
    Which one keepsthe water?? Which one is preferred?? (A) (B) (C) (D) Of course this one!!
  • 3.
    The dish keepsthe water or water keeps the dish??? Of course the dish keeps the water
  • 4.
    To keep thedata, we need something like a dish in java Variables can help us here They act like the dish We must define the type of every variable/ dish that holds the data
  • 5.
    Analyze it, whichone is the water and which one is the dish and which one is the type of the dish?? int x = 10 ; int 10 = x ; So is it right or wrong?? Data type Variable/ dish Data
  • 6.
    Primitive data types integral(‫)صحیح‬ floating point(‫)اعشاری‬ Boolean Byte short int long 8-bit 16-bit 32-bit 64-bit Float double 32-bit 64-bit True false
  • 7.
    Compute the circlearea formula (𝑎𝑟𝑒𝑎 = 𝜋𝑟2) 1- data holders (variables, constant) 2- assign value and calculate the area 3- display the result
  • 8.
    circle area public classCircleArea { public static void main(String[] args) { // Declare and initialize the variables double r=10; final double PI= 3.1415; // calculate the circle area double area = PI*r*r; // display the result System.out.print("This is the area of circle: "+area +" u263A"); } }
  • 9.
    Practice in theclass Get area of a square Formula( area = 𝑎2 ) public class Squarearea { public static void main(String[] args) { //Declare variables double a; double area; // Assign value a=3; // get the square area area=a*a; // display the result System.out.println("The area of Square with length " +a+ " is: "+ area); } }
  • 10.
    Assignment Compute the areaof Triangle A = hbb 𝟐 Compute the rectangle area A= width* length
  • 11.
    Rectangle area public classRectangle { public static void main(String[] args) { int l = 20; int w =10; int area = l * w; System.out.println("The area of rectangle is: "+ area); } }