{ "@context": "https://schema.org", "@type": "Organization", "name": "Brainscape", "url": "https://www.brainscape.com/", "logo": "https://www.brainscape.com/pks/images/cms/public-views/shared/Brainscape-logo-c4e172b280b4616f7fda.svg", "sameAs": [ "https://www.facebook.com/Brainscape", "https://x.com/brainscape", "https://www.linkedin.com/company/brainscape", "https://www.instagram.com/brainscape/", "https://www.tiktok.com/@brainscapeu", "https://www.pinterest.com/brainscape/", "https://www.youtube.com/@BrainscapeNY" ], "contactPoint": { "@type": "ContactPoint", "telephone": "(929) 334-4005", "contactType": "customer service", "availableLanguage": ["English"] }, "founder": { "@type": "Person", "name": "Andrew Cohen" }, "description": "Brainscape’s spaced repetition system is proven to DOUBLE learning results! Find, make, and study flashcards online or in our mobile app. Serious learners only.", "address": { "@type": "PostalAddress", "streetAddress": "159 W 25th St, Ste 517", "addressLocality": "New York", "addressRegion": "NY", "postalCode": "10001", "addressCountry": "USA" } }

Learning Unit 7 Programming Theory Flashcards

(13 cards)

1
Q

Coding Programs with If Statements

A
  • If and else are reserved words, IDE may indicate this by putting them in a different color.
  • Pseudocode
    begin
    _____________________
    if ____________________
    then_________________
    else_________________
    end if
    _____________________
    end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Relational Operators

A
  • Double equals in Java is used to check equality.
  • Single equals sign is used to assign/store a value in a variable.
  • ! used for Not.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Important points on the If statement

A
  • If…else is 1 statement in Java
  • Condition in an if statement can either be:
    True
    False
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Important that the layout of an if statement

A

Makes it easy to read.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

If there is one statement in a block

A

Curly brackets can be left off.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Objects of string data type cannot be compared using ==:

A

String is not a primitive data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Else is optional:

A

No else, program continues with the next instruction after the end of if statement block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When to use a Nested if:

A
  • Use an else if only one of the conditions can be true at the same time, so the program doesn’t check every if statement unnecessarily.
  • Do not use an else: there is more that one condition to be tested and the conditions are independent of each other.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why are ‘a’ and ‘A’ not the same in Java?

A
  • When Java compares the 2 letters, it compares their Unicode code values and not the actual characters.
  • Since ‘a’ and ‘A’ don’t have the same Unicode values, the computer sees them as 2 totally different characters.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How are conditions evaluated in Java

A

Arithmetic and logical expressions are evaluated as sums by the Arithmetic Logic Unit (ALU) in the processor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The NOT(!) operator

A

&& makes your program more efficient.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

|| Conditional OR:

A

Java will always carry out logical operators in the following order:
- Brackets
- NOT
- AND
- OR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A problem when using If Statement - A Valueless Variable

A
  • When a variable is only given a value in the if statement blocks: if none of the if statement are true Java knows that the variable will not get a value.
  • Any variable that is only assigned a value in if statements must be initialized before the if statement so that it definitely gets a value in the program.
  • No.s are usually assigned to 0
  • Strings are initialized to an empty string.
  • Characters cannot be initialized to nothing: must be character.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly