CS 121 Lecture Notes - Lecture 15: Quadratic Equation, Exponentiation

16 views3 pages

Document Summary

Random class: part of the java. util package. Provides methods that generate random #s: nextint() Scanner scan = new scanner(system. in); int a = scan. nextint( ); Random generator = new random( ); int b = generator. nextint( ); A: we can use another method of the random class: nextint(num) int a = generator. nextint( ); generator. nextint(11), nextint(6)generates a random integer w/ in [0,5, nextint(6)+1 generates a random integer w/in [0,6] Nextfloat() returns a random decimal value between 0. 0(inclusive) & 1. 0(exclusive) A: object invokes these methods, object provides service. num 1 = generator. nextint(10)+1; System. out. println ( from 1 to 10: + num1); System. out. println ( from 20 to 34: + num1); num 1 = generator. nextint(20)-10; System. out. println ( from -10 to 9: + num1); num 2 = generator. nextfloat(); System. out. println ( a random float (between 0-1): + num2); num2 = generator. nextfloat() * 6; // to 0. 0 to 0. 59999 num1 = (int)num2 + 1; Math class: provides a large # of basic mathematical functions that are helpful in making calculations.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents