Java for Fucking Idiots: Learn the Basics of Java Programming Without any experience!



Download 3,91 Mb.
Pdf ko'rish
bet16/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   12   13   14   15   16   17   18   19   ...   70
Bog'liq
Java for Fucking Idiots

boolean
imBored =
true
;
boolean
imHungry =
false
;
//True
boolean
imGoingToEatFood = imBored || imHungry;
See how the or operator || works? “I am going to eat food if I’m bored or if
I’m hungry.”
If either one of those conditions are true, then 
imGoingToEatFood
is set to
true.
More examples…
I’m making a text-based adventure game. If the user types in “exit”
or “done”, I exit the program.
I’m making a program to monitor the stock market (this is where
money lives and dies). If the price of a stock I own goes severely
up, or severely down, I send out an email alert.
In fact, Java won’t even look at the right side of the || operator if the left
side is already true; there’s no point! Java’s like… why check 
imHungry
if I
already know 
imBored
is enough to warrant eating food?
And
That’s not true when it comes to the and (&&) operator. Both need to be
true for the expression to evaluate to true.


boolean
wellRested =
true
;
boolean
motivated =
false
;
//False
boolean
goingToWorkOut = wellRested && motivated;
Even if I’m well rested, if I have no motivation at all, I won’t work out.
And even if I were motivated to work out, if I have no energy due to lack of
sleep, I’ll probably pass as well.
More examples…
I’m writing an app where the user must log in using their account
information. I only try to sign them in if they’re entered a
username and they’re entered a password.
I’m creating a lighting system that automatically turns off the
lights if the lights are currently on and there has been no one in
the room for 5 minutes.
Seem too easy? It’s “logical”, right? Get it? Logical? Because they’re called
the logica-
Oh, and just like with the math operators; no, you shouldn’t create variables
that are always true, or always false. They’re variables. But I’m trying to
get the concept across right now, kay? More on this when we get into
conditionals and if statements.
The assignment operator!
“Now, are you men ready for your super…special…. secret…
ASSIGNMENT!?!?
The two of you are to paint the inside of me house!!
Yayyyyy!!” – Spongebob SquarePants
Yeah, you’ve already seen this thing (it’s the equals sign = ), but we’re
going to cover it to clear up a misconception that beginners might make.
Think back to your algebra class in school. You probably don’t remember.
No, it’s not the one with the triangles… does this ring a bell?


x = 7
How would you say that out loud? Probably something like this:
“x is equal to 7”.
You can do something very similar in Java. Check out this line of code:
int
x =
7
;
It’s the same thing as before, right? “x is equal to 7”??
FALSE!
INCORRECT
!
NEGATIVE
!
Wanna see why? What if I show you this?
int
x =
1
;
Okay, x is 1…
x = x +
1
Hmm…
Okay, now x is equal to…. x + 1?? Wait… if x is 1, then that means 1 = 1 +
1??
Does that mean that 1 = 2???
Hopefully your mind has awoken from its slumber and is screaming at the
page: “THAT’S NOT POSSIBLE! THAT MAKES NO SENSE! WHY
WOULD THEY MAKE BRAN KING?”
= is not “is equal to”
That’s because a single equals sign in Java is the assignment operator .
Here’s how it works:
The thing on the left is given the value of the thing on the right. You can say
it like this instead:
int
x =
7
;
“Assign to x the value of 7”


x = x +
1
“Assign to x the current value of x plus 1”
Guess what? The value of x is 8 now (shocked emoji).
It seems like a subtle distinction, doesn’t it? “Assigning something a value,”
versus saying that “something is equal to something else.” But this concept
is a mystery mouseketool; a surprise tool that will help us later.
The relational operators!
Remember the carrot symbols (< and >)? Maybe you were taught to think
of them as alligators; the alligator’s mouth points to the bigger number?
Maybe? Anyway…
Here’s some true statements in regular math:
2 < 3
2 is less than 3.
5 > 4
5 is greater than 4.
Cool. Now, this is wrong.
5 > 5
5 is greater than 5.
They’re the same value; 5 is not bigger than 5. FALSE, you must be
screaming right now!
Now, what if we wrote this down?
5 ≥ 5
This is true. 5 is indeed greater than or equal to the value of 5. The
statement 5 ≥ 4 is also true.
Now that I’ve summarized the entirety of your 6th grade algebra class, let’s
see how this works in Java.
Relations!


//True

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   12   13   14   15   16   17   18   19   ...   70




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish