Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
Last active February 6, 2023 13:53
Show Gist options
  • Select an option

  • Save udacityandroid/30774906a4fc87b31d0b to your computer and use it in GitHub Desktop.

Select an option

Save udacityandroid/30774906a4fc87b31d0b to your computer and use it in GitHub Desktop.
Android for Beginners : If/Else Email Quiz
int numberOfEmailsInInbox = 0;
int numberOfDraftEmails = 2;
String emailMessage = "You have " + numberOfEmailsInInbox + " emails. ";
String draftMessage = "You have " + numberOfDraftEmails + " email drafts.";
if (numberOfEmailsInInbox == 0) {
emailMessage = "You have no new messages. ";
}
if (numberOfDraftEmails == 0) {
draftMessage = "You have no new drafts.";
}
Log.v("InboxActivity", emailMessage);
Log.v("InboxActivity", draftMessage);
@Gaganindoriya
Copy link
Copy Markdown

You have no new messages
You have 2 email drafts

@shoooka
Copy link
Copy Markdown

shoooka commented May 15, 2018

Please don't put the answers in the comments. There are still people that are taking this course. Let them learn.
ok i do

@arnolde
Copy link
Copy Markdown

arnolde commented May 28, 2018

I can't believe how many people are too dumb to have understood the rules (no answer posting) by now... it's pretty far into the course already... hope they get disqualified ;-)

@ahossam88
Copy link
Copy Markdown

I solve it

@MohEbaid
Copy link
Copy Markdown

You have no new messages.
You have 2 email drafts.

@mudathirlawal
Copy link
Copy Markdown

I first got confused because I forgot that their is a special IF structure for when the variable, numberOfEmailsInInbox, holds a value of 0.
And, so, I expected the displayed string to be: "You have 0 emails"; but, I quickly understood the thought process once I looked at the code
again and noticed the IF structure:
if (numberOfEmailsInInbox == 0) {
emailMessage = "You have no new messages. ";
}
It is quite a cool code!

@Fury4hwxc
Copy link
Copy Markdown

thanks 👍

@dantj007
Copy link
Copy Markdown

The answer is option C.
You have no new messages.
You have 2 email drafts.

@Tchybooxur
Copy link
Copy Markdown

Clearly C

@emanhamad
Copy link
Copy Markdown

C

@YassineOuardini
Copy link
Copy Markdown

C

@AhmedMohammed11
Copy link
Copy Markdown

You have no new messages.
You have 2 email drafts.

@allouane
Copy link
Copy Markdown

allouane commented Jun 4, 2020

You have no new messages.
You have 2 email drafts.

@mixspark
Copy link
Copy Markdown

ok

@zake0000
Copy link
Copy Markdown

zake0000 commented Apr 7, 2021

الكل يكتب الاجابة اصبحتوا علماء فالبرمجة الان ههه مفيش حد هيفهمني انان عارف غير لو عربي طبعا

@Harriskobia
Copy link
Copy Markdown

Option C is correct:

V/InboxActivity : You have no new messages.
V/InboxActivity : You have 2 email drafts.

@adiupd123
Copy link
Copy Markdown

V/InboxActivity: You have no new messages.
V/InboxAcitivity: You have 2 email drafts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment