Chapter 4--arrays, Loops, Logic Flashcards

(19 cards)

0
Q

How do you add elements to the array?

A
Integer[] booger=new Integer[2];
booger[0]=new Integer(2);
booger[1]=new Integer(7);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

Can you have different data types in am array?

A

No

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

What is the default value for integers?

A

Zero

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

Variable scope?

A

The part of a program where a variable exists and can be used

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

Create a basic if statement that prints a string if specific conditions exist.

A

if ( farts.length>1{
System.out.println(“yizznar”);
}

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

Code a basic if else statement

A
String jomama;
int holesfilled;
if (holesfilled=1){
    System.out.println("mom banged!")
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a common mistake when programming loops?

A

Putting a semicolon at the end of the for statement. This should only be done if the loop needs no body.

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

Give the basic format for a loop, and code a short loop

A

for (initialization; test; increment){
statement;
}

int age;
for (age=0; age);

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

what does System.out.format do?

A

Prints with number formatting

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

Is else if at the same tab level as if?

A

Yes

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

What are the data types usable as the test variable for a switch?

A

byte, short, int, char, String class

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

Code a basic switch

A
int dicksize=6;
switch (dicksize){
    case 4:
        System.out.println("it\'s small");
        break;
    case 12:
        System.out.println("it\'s big");
        break;
    default:
        System.out.println("it\'s meh");
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Code a switch where multiple values need to execute the same statement.

A
int dicksize=6;
switch (dicksize){
    case 1:
    case 2:
    case 3:
    case 4:
        System.out.println("it\'s small");
        break;
    case 12:
        System.out.println("it\'s big");
        break;
    default:
        System.out.println("it\'s meh");
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Give the format of a ternary operator, and code an example.

A

test ? trueresult : falseresult;

if the test is true, the trueresult is returned. Otherwise, the falseresult is returned. e.g.,

int vern=oBama>rOmney ? truth : lies;

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

How do you create an array the shortcut way?

A

int[] butthead={1994, 2007, 2017};

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

Code a while loop

A

while dick<15{
dick=dick+1;
}

16
Q

Code a do-while loop

A
int vern=7;
do{
    vern+=7;
    System.out.println(vern + " ");
}while (vern<49);
17
Q

What are the values in an array Initialized to? Numeric, Boolean, char, and objects

A

Zero, false, ‘\0’, and null

18
Q

When you move around values in an array of objects, are you copying values, or reassigning references? Are there exceptions to this?

A

Reassigning references. String objects are the exception