Varia Flashcards

1
Q

Tehe kahe int vahel

A

Tulemus alati int

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

Tehtes on üks double

A

Tulemus alati double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
int a = 10;
int b = 3;
(double) a / b =
A

double 3.3333333333333335

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
int a = 10;
int b = 3;
(double) (a / b) = 
A

double 3.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
double aa = 10.0; double bb = 3.0;
(int) aa / bb = 
A

double 3.3333333333333335

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
double aa = 10.0; double bb = 3.0;
(int) aa / (int) bb =
A

int 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
double aa = 10.0; double bb = 3.0;
(int) (aa / bb) =
A

int 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
int a = 10
var c = 3
var x = (double) (a / b) =
A

double 3.0

In Java, when declaring a variable as var, the compiler will
look for the type of the variable on the right side of the
expression. Here it can see it’s int 3, so var c is same as int
3. And a / b becomes an equation between two ints 10 / 3 = 3.
Though the casting (double) makes them become 3.0. And var x
becomes the equivalent of a double 3.0.

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

ValueRange maksimum
on ___

A

Kaasaarvatud.

ValueRange.of(0, 2).isValidIntValue(2) == true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Mida prindib kood?

for (int i = 1; i++ < 5; i--) { System.out.print(i); }

A

If it’s i++, i=1 is checked, but immediately after it passes into the loop, it becomes 2 and 2 is printed. i—Only happens in the end of the loop. If it were ++i, it would become 2 already prior to the condition check.

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

Kuidas kontrollida, et BigDecimal money väärtus ei ole väiksem kui 0?

A

money.compareTo(BigDecimal.ZERO) < 0
Comparison returns -1 if the first value is less than the other value, 0 if equal,
1 if greater.

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

Round double value moviePrice to 2 decimal places using BigDecimal.

A

// Round to 2 decimal places: // 13.3555 -> 13.36 return moviePrice.setScale(2, RoundingMode.HALF_UP);
It’s the best way to round everything, but project has to use Java 17 to do so.

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

What are A, B, C values in the end?

int A = 3, B = 3, C = 0;
while (A-- > 0) {
    while (B-- > 0) {
        if (A + B == A) {
            C += A;
        }
    }
    if (A + B == B) {
        C += B;
    }
}
A

A = -1, B = -3, C = -1

  1. First while loop: A=3 passes and is decremented to 2.
  2. Second while loop: B=3 passes and is decremented to 2.
  3. If sentence (2 + 2 == 2): Doesn’t start.
  4. Second while loop: B=2 passes and is decremented to 1.
  5. If sentence (2 + 1 == 2): Doesn’t start.
  6. Second while loop: B=1 passes and is decremented to 0.
  7. If sentence (2 + 0 == 2): Starts. C = 2.
  8. SECOND WHILE LOOP IS CHECKED ONE LAST TIME. B=0 doesn’t pass but is decremented to -1.
  9. If sentence (2 - 1 = -1): Doesn’t start.
  10. First while loop: A=2 passes and is decremented to 1.
  11. Second while loop: B=-1 doesn’t pass but is decremented to -2.
  12. If sentence (1 - 2 = -2): Doesn’t start.
  13. First while loop: A=1 passes and is decremented to 0.
  14. Second while loop: B=-2 doesn’t pass but is decremented to -3
  15. If sentence (0 - 3 = -3). Starts. C = -1.
  16. FIRST WHILE LOOP IS CHECKED ONE LAST TIME. A=0 doesn’t pass but is decremented to -1.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly