SlideShare a Scribd company logo
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);
}
}

More Related Content

PPSX
Data types, Variables, Expressions & Arithmetic Operators in java
PDF
Java apptitude-questions-part-1
PPTX
03 and 04 .Operators, Expressions, working with the console and conditional s...
PDF
vJUG Getting C C++ performance out of java
PDF
Devoxx MA 2015 - Turn you java objects into binary
PDF
9th_Computer Full Exercise
PPTX
Walt Disney Animators
PPT
Communication barriers
Data types, Variables, Expressions & Arithmetic Operators in java
Java apptitude-questions-part-1
03 and 04 .Operators, Expressions, working with the console and conditional s...
vJUG Getting C C++ performance out of java
Devoxx MA 2015 - Turn you java objects into binary
9th_Computer Full Exercise
Walt Disney Animators
Communication barriers

More from Nooria Esmaelzade (6)

PPTX
one smile can be the key to open everyone s heart
PPSX
Why we need to control scope
PPTX
Easy practice with if statement and boolean type
PPTX
Easy practice with current timemillis method
PPTX
Easy java key definition & practice
PPTX
Easy java installation & practice
one smile can be the key to open everyone s heart
Why we need to control scope
Easy practice with if statement and boolean type
Easy practice with current timemillis method
Easy java key definition & practice
Easy java installation & practice
Ad

Recently uploaded (20)

PPTX
show1- motivational ispiring positive thinking
PDF
Attachment Theory What Childhood Says About Your Relationships.pdf
PPTX
Learn how to prevent Workplace Incidents?
PDF
Elle Lalli on The Role of Emotional Intelligence in Entrepreneurship
PPTX
cấu trúc sử dụng mẫu Cause - Effects.pptx
PPTX
Personal Development - By Knowing Oneself?
PPTX
PERDEV-LESSON-3 DEVELOPMENTMENTAL STAGES.pptx
PDF
Top 10 Visionary Entrepreneurs to Watch in 2025
PPTX
UNIVERSAL HUMAN VALUES for NEP student .pptx
PPTX
Travel mania in india needs to change the world
PDF
The Spotlight Effect No One Is Thinking About You as Much as You Think - by M...
PPTX
SELF ASSESSMENT -SNAPSHOT.pptx an index of yourself by Dr NIKITA SHARMA
DOCX
Boost your energy levels and Shred Weight
PPTX
Identity Development in Adolescence.pptx
PPTX
How to Deal with Imposter Syndrome for Personality Development?
PDF
The Power of Pausing Before You React by Meenakshi Khakat
PPTX
Presentation on interview preparation.pt
PDF
Red Light Wali Muskurahat – A Heart-touching Hindi Story
PDF
The Zeigarnik Effect by Meenakshi Khakat.pdf
PPTX
Commmunication in Todays world- Principles and Barriers
show1- motivational ispiring positive thinking
Attachment Theory What Childhood Says About Your Relationships.pdf
Learn how to prevent Workplace Incidents?
Elle Lalli on The Role of Emotional Intelligence in Entrepreneurship
cấu trúc sử dụng mẫu Cause - Effects.pptx
Personal Development - By Knowing Oneself?
PERDEV-LESSON-3 DEVELOPMENTMENTAL STAGES.pptx
Top 10 Visionary Entrepreneurs to Watch in 2025
UNIVERSAL HUMAN VALUES for NEP student .pptx
Travel mania in india needs to change the world
The Spotlight Effect No One Is Thinking About You as Much as You Think - by M...
SELF ASSESSMENT -SNAPSHOT.pptx an index of yourself by Dr NIKITA SHARMA
Boost your energy levels and Shred Weight
Identity Development in Adolescence.pptx
How to Deal with Imposter Syndrome for Personality Development?
The Power of Pausing Before You React by Meenakshi Khakat
Presentation on interview preparation.pt
Red Light Wali Muskurahat – A Heart-touching Hindi Story
The Zeigarnik Effect by Meenakshi Khakat.pdf
Commmunication in Todays world- Principles and Barriers
Ad

Easy practice with java variables

  • 1. Easy practice with java variables Java programming Nooria Esmaelzade 2016
  • 2. Which one keeps the water?? Which one is preferred?? (A) (B) (C) (D) Of course this one!!
  • 3. The dish keeps the water or water keeps the dish??? Of course the dish keeps the water
  • 4. 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
  • 5. 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
  • 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 circle area formula (𝑎𝑟𝑒𝑎 = 𝜋𝑟2) 1- data holders (variables, constant) 2- assign value and calculate the area 3- display the result
  • 8. 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"); } }
  • 9. 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); } }
  • 10. Assignment Compute the area of Triangle A = hbb 𝟐 Compute the rectangle area A= width* length
  • 11. 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); } }