Kapitel 3 Flashcards

1
Q

1

A

if (y == 20)

x = 0;

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

2

A

if (hours > 40)

payRate *= 1.5;

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

3

A

if (sales >= 10000)

commission = 0.2;

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

4

A

if (max)

fees = 50;

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

5

A
if (x > 100)
{
y = 20;
z = 40;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

6

A
if (a < 10)
{
b = 0;
c = 1;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

7

A

if (myCharacter == ‘D’)

System.out.println(“Goodbye”);

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

8

A

if (x > 100)
y = 20;
else
y = 0;

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

9

A

if (y == 100)
x = 1;
else
x = 0;

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

10

A

if (sales >= 50000.0)
commission = 0.2;
else
commission = 0.1;

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

11

A
if (a < 10)
{
b = 0;
c = 1;
}
else
{
b = -99;
c = 0;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

12

A

1 1

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

13

A

If the customer purchases this many coupons are
this many books . . . given.
1 1
2 1
3 2
4 2
5 3
10 3

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

14

A
if (amount1 > 10)
{
if (amount2 < 100)
{
if (amount1 > amount2)
System.out.println(amount1);
else
System.out.println(amount2);
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

15

A
if (x > 0)
{
if (y < 20)
{
z = 1;
}
else
{
z = 0;
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

16

A

Logical Expression Result (true or false)
true && false false
true && true true
false && true false
false && false false
true || false true
true || true true
false || true true
false || false false
!true false
!false true

17
Q

17

A

T, F, T, T, T

18
Q

18

A

if (speed >= 0 && speed );

19
Q

19

A

if (speed < 0 || speed > 200)

System.out.println(“The number is not valid”);

20
Q

20

A

if (name.equals(“Timothy”))

System.out.println(“Do I know you?”);

21
Q

21

A

if (name1.compareTo(name2) < 0)
System.out.println(name1 + “ “ + name2);
else
System.out.println(name2 + “ “ + name1);

22
Q

22

A

if (name.equalsIgnoreCase(“Timothy”))

System.out.println(“Do I know you?”);

23
Q

23

A

a) z = x > y ? 1 : 20;
b) population = temp > 45 ? base * 10 : base * 2;
c) wages = hours > 40 ? wages * 1.5 : wages * 1;
d) System.out.println(result >=0 ? “The result is positive” :
“The result is negative”);

24
Q

24

A
// Here is the switch statement.
switch(userNum)
{
case 1 : System.out.println("One");
break;
case 2 : System.out.println("Two");
break;
case 3 : System.out.println("Three");
break;
default: System.out.println("Error: invalid number.");
}
25
Q

25

A

switch(selection)
{
case ‘A’ : System.out.println(“You selected A.”);
break;
case ‘B’ : System.out.println(“You selected B.”);
break;
case ‘C’ : System.out.println(“You selected C.”);
break;
case ‘D’ : System.out.println(“You selected D.”);
break;
default : System.out.println(“Not good with letters, eh?”);
}

26
Q

26

A

Because it uses greater-than and less-than operators in the comparisons.

27
Q

27

A

The case expressions must be a literal or a final variable, which must be of the
char , byte , short , or int types. In this code, relational expressions are used.

28
Q

28

A

That is serious.

29
Q

29

A

System.out.printf(“%,.2f”, number);

30
Q

30

A

System.out.printf(“%10.1f”, number);

31
Q

31

A

System.out.printf(“%08.1f”, number);

32
Q

32

A

System.out.printf(“%,10d”, number);

33
Q

33

A

System.out.printf(“%-,20.2f”, number);

34
Q

34

A

System.out.printf(“%20s”, name);

35
Q

35

A

“00000.000”

36
Q

36

A

”#.00”

37
Q

37

A

”#,###,##0.00” or “0,000,000.00”