Search Header Logo
compareTo and Math.random

compareTo and Math.random

Assessment

Presentation

Computers

10th Grade - University

Hard

Created by

Brian Ciavarella

Used 2+ times

FREE Resource

5 Slides • 8 Questions

1

compareTo method for String class

Slide image

2

Multiple Choice

Given that str1 has a value of: "Galaga", and str2 has a value of: "The Legend of Zelda", what is the returned value of str1.compareTo(str2)?

1

Positive

2

Negative

3

Multiple Choice

Given that str1 has a value of: "Bubble Bobble", and str2 has a value of: "The Legend of Zelda", what is the returned value of str2.compareTo(str1)?

1

Positive

2

Negative

4

Multiple Choice

Given that str1 has a value of: "Tetris", and str2 has a value of: "Donkey Kong Country", what is the returned value of str1.compareTo(str2)?

1

Positive

2

Negative

5

Multiple Choice

Given that str1 has a value of: "Mike Tyson's Punch Out!!", and str2 has a value of: "Doom", what is the returned value of str1.compareTo(str2)?

1

Positive

2

Negative

6

Multiple Choice

What type of value is returned by: "Contra".compareTo("Sonic the Hedgehog") ?

1

Positive

2

Negative

3

Error, you can only use compare to on variables that hold Strings.

7

Random Integers with Math.random()

Review

Slide image

8

Random Integers with Math.random()

  • Math.random() -> [0 ,1)

  • (int)Math.random() -> 0

  • (int)(Math.random() * a) -> [0 , a) = [0 , a-1]

  • (int)(Math.random() * a + b) -> [b , a + b) = [b , a + b - 1]

  • (int)(Math.random() * (max - min + 1) + min) -> [min , max]

9

Multiple Choice

What is the range of possible integers generated by:

(int)(Math.random() * 3 + 1)?

1

[0 , 4]

2

[1 , 4]

3

[1 , 3]

4

[1 , 2]

10

Fill in the Blanks

Type answer...

11

Fill in the Blanks

Type answer...

12

Escape the Room...

random integer edition

https://docs.google.com/forms/d/e/1FAIpQLSc1LPu_sTPlIjdFAf-McrE-uh4of2DFgqtx9QawUy29-iHB7w/viewform?authuser=0

Slide image

13

Slide image

Escape the Room... random integer edition

https://docs.google.com/forms/d/e/1FAIpQLSc1LPu_sTPlIjdFAf-McrE-uh4of2DFgqtx9QawUy29-iHB7w/viewform?authuser=0

compareTo method for String class

Slide image

Show answer

Auto Play

Slide 1 / 13

SLIDE