Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
A bullet is only useful if you write it as a comparison.
So far, we covered every data type.
There are more, but these are the most common int long double drinka and bullion.
Now all of these types look like they serve a purpose.
But what's useful about a variable that can only store true or false?
Well, the way that you learn how to store them is pretty useless, a boolean value is only useful if
in the form of a comparison.
So in this lesson, you're going to write comparisons that return either true or false.
First thing I'm going to do is create a new class inside the section refold or create a new file named
Boolean comparison's Java and in the Boolean comparisons class, make sure it has the main method.
So what is a comparison, a comparison compares to values, then it returns true or false?
So instead of writing static, true or false values, a comparison will return true if what you write
is true and conversely, it's going to return false if what you write is false.
So, for example, this first comparison checks a five is bigger than one.
That is true.
The second comparison checks of five is less than one.
This is false.
And there are eight types of comparisons we can make greater than less than greater than or equal to
less than or equal to, equal to not equal to equal to four string values and not equal to four string.
We're going to go through all of them, but first we'll start by discussing the greater than comparison.
This comparison involves a value on the left be greater than comparison, any value on the right.
The greater then operator compares the value on the left to the value on the right.
If the value on the left is greater, the comparison returns true.
If not, the comparison is false.
You can compare any type of value like int longer double, so we'll start by making two and variables
int chemistry grade.
Is equal to 95 and into biology grade is equal to 75.
Now, your friend Harry wants to check if he did better in biology, and we're going to help him out.
We're going to check if biology grade.
Is greater than chemistry grade.
And as I run my code.
And this clearly is false.
Java checks, if Buyology great is greater than chemistry and this comparison is not true, it's false.
You can also compare decimals, so we're going to make two double variables, double sales is equal
to thirty seven point five five.
And double castes is equal to 5.5 five.
And we're going to check if the school made money, that is our sales greater than costs.
So we're going to print the comparison of checking sales being greater than costs.
We're going to run the code.
And as we do, this is a true comparison, sales are greater than costs.
You greater than comparison returns, true, because the value on the left is greater than the value
on the right.
Onto the less than comparison.
This comparison involves a value on the left, the less than operator and the value on the right now,
less then compares the value on the left to the value on the right.
If the value on the left is less, the comparison is true.
Otherwise, the comparison returns false.
So we're going to reverse the grittier then comparisons with less than.
Rerun our code.
And accordingly, the first comparison is true and the second one is false.
The first comparison is true because biology grade is indeed less than the chemistry grade.
The second comparison checks if sales are less than costs and this is false.
All right, now we're going to remove the sales and cost variable because we're not going to need them
anymore.
Onto the greater than or equal to comparison.
Once again, this involves a value on the left, the greater than or equal to the operator, any value
on the rights would be greater than or equal to comparison checks if the value on the left is greater
than or equal to the value on the rights.
If so, the comparison is true, and if not, the comparison is false.
So we're going to add a new variable English grade and we're going to set it equal to seventy five.
And we're going to check if chemistry grade.
Is greater than or equal to the English great.
Runnier code.
And this comparison returns true, that's because chemistry grade, the value on the left is greater
than Englis grade, which results in a true comparison.
Now we're going to compare it with the biology grade.
So check if biology grade is greater than or equal to English grade.
Run your code.
And once again, this is the comparison is true because English grant is equal to biology grade.
Onto the less than or equal to comparison this one checks, if I'm sure you get the pattern by now,
there is a value on the left the less than or equal to comparison, any value on the right.
And you can probably assume what this does.
So we're going to switch every operator with a less than or equal to comparison.
We run our code.
And that's interesting, the comparison returns false then true.
The first comparison checks, if chemistry rate is less than or equal to wingless grade, this is false
because chemistry grade is greater.
And the second comparison is true, because biology grade is indeed equal to English grade.
And now there's the equal comparison which returns true, if the values are equal, it returns false.
Otherwise, as always, there's a value on the left, the double equals sign any value on the rights.
So we're going to replace every operator with the equals comparison.
Rerun your code.
And we get the same results, but for different reasons, the first comparison checks if chemistry grade
is equal to English grade, which is false, and biology grade is indeed equal to the English grade.
So that returns true.
Onto the not equal comparison, the exclamation mark in Java means not this makes our operator the not
equal comparison and do not equal comparison returns.
True, if the values are not equal, it returns.
False if they are.
As you probably guessed, it involves a value on the left, the not equal comparison, any value on
the right.
So back in her coat, we're going to replace the operators with the not equal to comparison.
We're going to rerun our code.
And as you could predict, the results switch.
Now, the first comparison is true because chemistry does not equal to English grade.
And the second comparison checks at Balaji grade is not equal to English grade, and that's false.
They are equal.
The equals method checks, if string values are equal, the equals method is the same as the equal sign,
but it's four string values.
With that being said, never used the double equals sign or the not equal sine comparisons.
To compare string values, you will get inconsistent results.
The equals comparison four strings involves a string value on the left and equals method that checks
the string on the left is equal to the string on the right.
Any string value on the rights.
So we're going to make two string variables and assign them the same string value, string sentence.
We're going to set an equal to I love this course.
And we're going to make another variable that equals the same thing.
Now I'm going to compare them using the equals method.
We're going to print the result of checking if sentence equals sentence to.
We were on your code.
And this is indeed true, both strong values are equal.
And the last method we're going to look at is did not equals method, not equals method.
Checks of string values are not equal.
Remember that the exclamation mark in Java means not.
So this makes our method is not equals method.
So we're going to add an exclamation mark and we'll run honor code.
As we expect, the results should switch because the comparison checks, if the strong values are not
equal but the strong values are equal, so it's false.
Finally, I want to make sure that you don't confuse the equal signs with the single equal sign.
They are very, very different.
A single equal sign sets a variable equal to another value.
The equal sign is a comparison.
It compares to values and returns a boolean.
True or false?
In this lesson, you make comparisons that return true or false, instead of writing static, true or
false values, a comparison will return true.
If what you write is true, just like this comparison, any comparison will return false if what you
write is false.
You saw that there are eight comparison operators and in this lesson you made comparisons from all of
them.
Now you might be asking why are comparisons useful?
How can we use them?
Well, stick around as we expand into F.L. statements.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.