SlideShare a Scribd company logo
1 of 17
Easy practice with if
statement and Boolean type
Java programming
Nooria Esmaelzade
2016
Review to data types
74532573
723.3634
Maryam
This is a string.
A
int, short, byte, long
Float, double
String
char
But how you can save true or false values??
How do you save the result of comparison?
int x = 10;
int y = 20;
(X > Y ) ( X < Y ) (X = Y)
Primitive data types
integral (‫)صحیح‬ floating point(‫)اعشاری‬ Boolean (true, false)
Byte short int long
8-bit 16-bit 32-bit 64-bit
Float double
32-bit 64-bit
Boolean data type
A boolean is used to perform logical operations, most commonly to
determine whether some condition is true.
Boolean only can have two values :
True
false
Boolean example
public class testBoolean {
public static void main(String[] args) {
boolean b = true;
boolean b2 = false;
boolean b3 = b2;
System.out.println(b);
System.out.println(b2);
System.out.println(b3);
}
}
Boolean data type
The result of the comparison is a boolean value
int radius = 10;
Boolean example 2
public class testBoolean {
public static void main(String[] args) {
boolean b ;
int x = 10;
int y = 20;
b = x>y;
System.out.println(b);
System.out.println( x < y);
}
}
practice additions game
import java.util.Scanner;
public class AdditionQuiz {
public static void main(String[] args) {
int number2 = (int)(System.currentTimeMillis() * 7 % 10);
int number1 = (int)(System.currentTimeMillis() % 10);
int addition = number2 + number1;
Scanner input = new Scanner(System.in);
System.out.print( "What is " + number1 + " + " + number2 + " ? ");
int answer = input.nextInt();
boolean result = addition == answer;
System.out.println(number1 + " + " + number2 + " = " + answer + " is " +
result);
}
}
If statements
What do you think??
So???
If you are a good person
You will go to the heaven 
If you are a bad person
You will go to the hell 
How we use if in java
if (you are bad) {
you are in hell ;
You will be tortured;
}
if (you are good) {
you are in heaven;
You will enjoy;
}
Another example
Who succeeds and who fails ???
If the test score is greater than 55,
the student is passed
If the test score is less than 55,
the student is failed
How we use it in java
if (score > 55){
Student passed;
}
if (score < 55){
Student failed;
}
Simple program to check if student is passed or
failed
import java.util.Scanner;
public class passOrFail {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("Enter your score: ");
int score = input.nextInt();
if (score >= 55){
System.out.println("hahaha you are passed u263A");
}
if (score < 55){
System.out.println("Sorry you are failed u2639");
}
}
}
Homework
Write the program that ask the user to enter an integer number.
The program should check if it is odd or even.
If the number is even, print “the number is even”
Otherwise print, “the number is odd”

More Related Content

What's hot

Java - Class Structure
Java - Class StructureJava - Class Structure
Java - Class StructureVicter Paul
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaRadhika Talaviya
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptmanish kumar
 

What's hot (7)

Magic Literals in Pharo
Magic Literals in PharoMagic Literals in Pharo
Magic Literals in Pharo
 
Overview of Java
Overview of Java Overview of Java
Overview of Java
 
Java - Class Structure
Java - Class StructureJava - Class Structure
Java - Class Structure
 
Array
ArrayArray
Array
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops concept
 
2.oop concept
2.oop concept2.oop concept
2.oop concept
 

Viewers also liked

Why we need to control scope
Why we need to control scope Why we need to control scope
Why we need to control scope Nooria Esmaelzade
 
Easy java key definition &amp; practice
Easy java key definition &amp; practiceEasy java key definition &amp; practice
Easy java key definition &amp; practiceNooria Esmaelzade
 
Easy java installation &amp; practice
Easy java installation &amp; practiceEasy java installation &amp; practice
Easy java installation &amp; practiceNooria Esmaelzade
 
Easy practice with current timemillis method
Easy practice with current timemillis methodEasy practice with current timemillis method
Easy practice with current timemillis methodNooria Esmaelzade
 
Internet degli oggetti
Internet degli oggettiInternet degli oggetti
Internet degli oggettiAlex Fontana
 
Design and synthesis of novel protein kinase R (PKR) inhibitors
Design and synthesis of novel protein kinase R (PKR) inhibitorsDesign and synthesis of novel protein kinase R (PKR) inhibitors
Design and synthesis of novel protein kinase R (PKR) inhibitorssagiv weintraub
 
Paleo grubs book
Paleo grubs bookPaleo grubs book
Paleo grubs booksamcleve19
 
150915 Presentation at ChinaAdhesive 2015
150915 Presentation at ChinaAdhesive 2015150915 Presentation at ChinaAdhesive 2015
150915 Presentation at ChinaAdhesive 2015Maurice Zhu
 
правила безпечної поведінки дітей на канікулах
правила безпечної поведінки дітей на канікулахправила безпечної поведінки дітей на канікулах
правила безпечної поведінки дітей на канікулахOlga Savchenko
 
Easy practice with java variables
Easy practice with java variables Easy practice with java variables
Easy practice with java variables Nooria Esmaelzade
 
Java basics variables
 Java basics   variables Java basics   variables
Java basics variablesJoeReddieMedia
 

Viewers also liked (13)

Why we need to control scope
Why we need to control scope Why we need to control scope
Why we need to control scope
 
Easy java key definition &amp; practice
Easy java key definition &amp; practiceEasy java key definition &amp; practice
Easy java key definition &amp; practice
 
Easy java installation &amp; practice
Easy java installation &amp; practiceEasy java installation &amp; practice
Easy java installation &amp; practice
 
Easy practice with current timemillis method
Easy practice with current timemillis methodEasy practice with current timemillis method
Easy practice with current timemillis method
 
Internet degli oggetti
Internet degli oggettiInternet degli oggetti
Internet degli oggetti
 
Design and synthesis of novel protein kinase R (PKR) inhibitors
Design and synthesis of novel protein kinase R (PKR) inhibitorsDesign and synthesis of novel protein kinase R (PKR) inhibitors
Design and synthesis of novel protein kinase R (PKR) inhibitors
 
Dr. drum
Dr. drumDr. drum
Dr. drum
 
Paleo grubs book
Paleo grubs bookPaleo grubs book
Paleo grubs book
 
Mohammed Gad
Mohammed Gad Mohammed Gad
Mohammed Gad
 
150915 Presentation at ChinaAdhesive 2015
150915 Presentation at ChinaAdhesive 2015150915 Presentation at ChinaAdhesive 2015
150915 Presentation at ChinaAdhesive 2015
 
правила безпечної поведінки дітей на канікулах
правила безпечної поведінки дітей на канікулахправила безпечної поведінки дітей на канікулах
правила безпечної поведінки дітей на канікулах
 
Easy practice with java variables
Easy practice with java variables Easy practice with java variables
Easy practice with java variables
 
Java basics variables
 Java basics   variables Java basics   variables
Java basics variables
 

Similar to Easy practice with if statement and boolean type

Pi j1.3 operators
Pi j1.3 operatorsPi j1.3 operators
Pi j1.3 operatorsmcollison
 
Mutation testing - the way to improve unit tests quality
Mutation testing - the way to improve unit tests qualityMutation testing - the way to improve unit tests quality
Mutation testing - the way to improve unit tests qualityVadim Mikhnevych
 
Java căn bản - Chapter5
Java căn bản - Chapter5Java căn bản - Chapter5
Java căn bản - Chapter5Vince Vo
 
Java Foundations: Basic Syntax, Conditions, Loops
Java Foundations: Basic Syntax, Conditions, LoopsJava Foundations: Basic Syntax, Conditions, Loops
Java Foundations: Basic Syntax, Conditions, LoopsSvetlin Nakov
 
1 Midterm Preview Time allotted 50 minutes CS 11.docx
1  Midterm Preview Time allotted 50 minutes CS 11.docx1  Midterm Preview Time allotted 50 minutes CS 11.docx
1 Midterm Preview Time allotted 50 minutes CS 11.docxhoney725342
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaRasan Samarasinghe
 
Scjp questions
Scjp questionsScjp questions
Scjp questionsroudhran
 
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdf
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdfAll based on Zybooks = AP Java with zylabsPlease answer all questi.pdf
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdfdeepakarora871
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paperfntsofttech
 
ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.pptMahyuddin8
 
conditional statements
conditional statementsconditional statements
conditional statementsJames Brotsos
 
Absolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankAbsolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankLauriewest24
 

Similar to Easy practice with if statement and boolean type (20)

Ch4
Ch4Ch4
Ch4
 
Mutation Testing
Mutation TestingMutation Testing
Mutation Testing
 
Pi j1.3 operators
Pi j1.3 operatorsPi j1.3 operators
Pi j1.3 operators
 
130706266060138191
130706266060138191130706266060138191
130706266060138191
 
Mutation testing - the way to improve unit tests quality
Mutation testing - the way to improve unit tests qualityMutation testing - the way to improve unit tests quality
Mutation testing - the way to improve unit tests quality
 
DITEC - Programming with Java
DITEC - Programming with JavaDITEC - Programming with Java
DITEC - Programming with Java
 
Java căn bản - Chapter5
Java căn bản - Chapter5Java căn bản - Chapter5
Java căn bản - Chapter5
 
Java Foundations: Basic Syntax, Conditions, Loops
Java Foundations: Basic Syntax, Conditions, LoopsJava Foundations: Basic Syntax, Conditions, Loops
Java Foundations: Basic Syntax, Conditions, Loops
 
Java Programmin: Selections
Java Programmin: SelectionsJava Programmin: Selections
Java Programmin: Selections
 
Core java
Core javaCore java
Core java
 
1 Midterm Preview Time allotted 50 minutes CS 11.docx
1  Midterm Preview Time allotted 50 minutes CS 11.docx1  Midterm Preview Time allotted 50 minutes CS 11.docx
1 Midterm Preview Time allotted 50 minutes CS 11.docx
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in Java
 
Comp102 lec 5.1
Comp102   lec 5.1Comp102   lec 5.1
Comp102 lec 5.1
 
Scjp questions
Scjp questionsScjp questions
Scjp questions
 
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdf
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdfAll based on Zybooks = AP Java with zylabsPlease answer all questi.pdf
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdf
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.ppt
 
conditional statements
conditional statementsconditional statements
conditional statements
 
Java Quiz
Java QuizJava Quiz
Java Quiz
 
Absolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankAbsolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test Bank
 

Recently uploaded

Dhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service DhuleDhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service Dhulesrsj9000
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证kbdhl05e
 
social media chat application main ppt.pptx
social media chat application main ppt.pptxsocial media chat application main ppt.pptx
social media chat application main ppt.pptxsprasad829829
 
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Ahmedabad Escorts Girl Services For Male Tourists 9537192988
Ahmedabad Escorts Girl Services For Male Tourists 9537192988Ahmedabad Escorts Girl Services For Male Tourists 9537192988
Ahmedabad Escorts Girl Services For Male Tourists 9537192988oolala9823
 
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
Postal Ballot procedure for employees to utilise
Postal Ballot procedure for employees to utilisePostal Ballot procedure for employees to utilise
Postal Ballot procedure for employees to utiliseccsubcollector
 
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...ur8mqw8e
 
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ EscortsDelhi Escorts Service
 
西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做j5bzwet6
 
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndCall Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndPooja Nehwal
 
办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭o8wvnojp
 
Powerpoint on Writing a Newspaper Report.pptx
Powerpoint on Writing a Newspaper Report.pptxPowerpoint on Writing a Newspaper Report.pptx
Powerpoint on Writing a Newspaper Report.pptxNeelamMulchandani1
 
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 AvilableCall Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilabledollysharma2066
 
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfREFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfssusere8ea60
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改atducpo
 

Recently uploaded (20)

Dhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service DhuleDhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service Dhule
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证
 
social media chat application main ppt.pptx
social media chat application main ppt.pptxsocial media chat application main ppt.pptx
social media chat application main ppt.pptx
 
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Govindpuri Delhi 💯Call Us 🔝8264348440🔝
 
Ahmedabad Escorts Girl Services For Male Tourists 9537192988
Ahmedabad Escorts Girl Services For Male Tourists 9537192988Ahmedabad Escorts Girl Services For Male Tourists 9537192988
Ahmedabad Escorts Girl Services For Male Tourists 9537192988
 
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
 
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
 
Postal Ballot procedure for employees to utilise
Postal Ballot procedure for employees to utilisePostal Ballot procedure for employees to utilise
Postal Ballot procedure for employees to utilise
 
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
 
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
 
西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做
 
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndCall Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
 
办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭
 
Powerpoint on Writing a Newspaper Report.pptx
Powerpoint on Writing a Newspaper Report.pptxPowerpoint on Writing a Newspaper Report.pptx
Powerpoint on Writing a Newspaper Report.pptx
 
🔝9953056974🔝!!-YOUNG BOOK model Call Girls In Aerocity Delhi Escort service
🔝9953056974🔝!!-YOUNG BOOK model Call Girls In Aerocity Delhi Escort service🔝9953056974🔝!!-YOUNG BOOK model Call Girls In Aerocity Delhi Escort service
🔝9953056974🔝!!-YOUNG BOOK model Call Girls In Aerocity Delhi Escort service
 
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 AvilableCall Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
 
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfREFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
 
young Call girls in Neb Sarai 🔝 9953056974 🔝 Delhi escort Service
young Call girls in Neb Sarai 🔝 9953056974 🔝 Delhi escort Serviceyoung Call girls in Neb Sarai 🔝 9953056974 🔝 Delhi escort Service
young Call girls in Neb Sarai 🔝 9953056974 🔝 Delhi escort Service
 
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road GurgaonCheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
 

Easy practice with if statement and boolean type

  • 1. Easy practice with if statement and Boolean type Java programming Nooria Esmaelzade 2016
  • 2. Review to data types 74532573 723.3634 Maryam This is a string. A int, short, byte, long Float, double String char
  • 3. But how you can save true or false values?? How do you save the result of comparison? int x = 10; int y = 20; (X > Y ) ( X < Y ) (X = Y)
  • 4. Primitive data types integral (‫)صحیح‬ floating point(‫)اعشاری‬ Boolean (true, false) Byte short int long 8-bit 16-bit 32-bit 64-bit Float double 32-bit 64-bit
  • 5. Boolean data type A boolean is used to perform logical operations, most commonly to determine whether some condition is true. Boolean only can have two values : True false
  • 6. Boolean example public class testBoolean { public static void main(String[] args) { boolean b = true; boolean b2 = false; boolean b3 = b2; System.out.println(b); System.out.println(b2); System.out.println(b3); } }
  • 7. Boolean data type The result of the comparison is a boolean value int radius = 10;
  • 8. Boolean example 2 public class testBoolean { public static void main(String[] args) { boolean b ; int x = 10; int y = 20; b = x>y; System.out.println(b); System.out.println( x < y); } }
  • 9. practice additions game import java.util.Scanner; public class AdditionQuiz { public static void main(String[] args) { int number2 = (int)(System.currentTimeMillis() * 7 % 10); int number1 = (int)(System.currentTimeMillis() % 10); int addition = number2 + number1; Scanner input = new Scanner(System.in); System.out.print( "What is " + number1 + " + " + number2 + " ? "); int answer = input.nextInt(); boolean result = addition == answer; System.out.println(number1 + " + " + number2 + " = " + answer + " is " + result); } }
  • 11. What do you think??
  • 12. So??? If you are a good person You will go to the heaven  If you are a bad person You will go to the hell 
  • 13. How we use if in java if (you are bad) { you are in hell ; You will be tortured; } if (you are good) { you are in heaven; You will enjoy; }
  • 14. Another example Who succeeds and who fails ??? If the test score is greater than 55, the student is passed If the test score is less than 55, the student is failed
  • 15. How we use it in java if (score > 55){ Student passed; } if (score < 55){ Student failed; }
  • 16. Simple program to check if student is passed or failed import java.util.Scanner; public class passOrFail { public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.println("Enter your score: "); int score = input.nextInt(); if (score >= 55){ System.out.println("hahaha you are passed u263A"); } if (score < 55){ System.out.println("Sorry you are failed u2639"); } } }
  • 17. Homework Write the program that ask the user to enter an integer number. The program should check if it is odd or even. If the number is even, print “the number is even” Otherwise print, “the number is odd”