computational expression
play

Computational Expression Random Class, Math Class, Wrapper Classes - PowerPoint PPT Presentation

Computational Expression Random Class, Math Class, Wrapper Classes Janyl Jumadinova 30 September, 2019 Janyl Jumadinova Computational Expression 30 September, 2019 1 / 8 Random Class The Random class is part of the java.util package It


  1. Computational Expression Random Class, Math Class, Wrapper Classes Janyl Jumadinova 30 September, 2019 Janyl Jumadinova Computational Expression 30 September, 2019 1 / 8

  2. Random Class The Random class is part of the java.util package It provides methods that generate pseudo-random numbers Janyl Jumadinova Computational Expression 30 September, 2019 2 / 8

  3. Random Class The Random class is part of the java.util package It provides methods that generate pseudo-random numbers Before you can use its methods, you must create an instance of the Random class Random rand = new Random( ); Janyl Jumadinova Computational Expression 30 September, 2019 2 / 8

  4. Random Class float nextFloat( ) float nextDouble( ) - Returns a random number between 0.0 inclusive and 1.0 exclusive. Janyl Jumadinova Computational Expression 30 September, 2019 3 / 8

  5. Random Class float nextFloat( ) float nextDouble( ) - Returns a random number between 0.0 inclusive and 1.0 exclusive. Random rand = new Random( ); float f; f = rand.nextFloat( ); Janyl Jumadinova Computational Expression 30 September, 2019 3 / 8

  6. Random Class int nextInt( ) - Returns a random number that ranges over all possible int values positive and negative. Janyl Jumadinova Computational Expression 30 September, 2019 4 / 8

  7. Random Class int nextInt( ) - Returns a random number that ranges over all possible int values positive and negative. Random rand = new Random( ); int num; num = rand.nextInt( ); Janyl Jumadinova Computational Expression 30 September, 2019 4 / 8

  8. Random Class int nextInt( ) - Returns a random number that ranges over all possible int values positive and negative. Random rand = new Random( ); int num; num = rand.nextInt( ); int nextInt( int num ) - Returns a random number between 0 (inclusive) and num (exclusive). Janyl Jumadinova Computational Expression 30 September, 2019 4 / 8

  9. Random Class int nextInt( ) - Returns a random number that ranges over all possible int values positive and negative. Random rand = new Random( ); int num; num = rand.nextInt( ); int nextInt( int num ) - Returns a random number between 0 (inclusive) and num (exclusive). Random rand = new Random( ); int num; num = rand.nextInt(5 ); Janyl Jumadinova Computational Expression 30 September, 2019 4 / 8

  10. Math Class Math plays a large role in computer programs. Because of this, there is an entire class (Math) that provides easy-to-use interfaces to many common mathematical methods. Unlike most other classes, the Math class is part of the java.lang package, which is imported automatically by the compiler when you compile a program. Therefore, you don’t need to do anything special in your program to have access to these methods. Janyl Jumadinova Computational Expression 30 September, 2019 5 / 8

  11. Math Class Math class consists of: static methods, which are methods that don’t depend on the contents of an object. static fields, which are values that are usually defined to be public, final and static, meaning that anyone can access them outside the package. Since their values are final, that means that they are constant and can’t be changed. Janyl Jumadinova Computational Expression 30 September, 2019 6 / 8

  12. Math Class Examples Janyl Jumadinova Computational Expression 30 September, 2019 7 / 8

  13. Wrapper Classes May want to have an object hold a simple primitive value. Janyl Jumadinova Computational Expression 30 September, 2019 8 / 8

  14. Wrapper Classes May want to have an object hold a simple primitive value. A wrapper class represents a particular primitive type. Janyl Jumadinova Computational Expression 30 September, 2019 8 / 8

  15. Wrapper Classes May want to have an object hold a simple primitive value. A wrapper class represents a particular primitive type. For example, Integer represents a simple integer value. An object created from the Integer class stores a single int value. Janyl Jumadinova Computational Expression 30 September, 2019 8 / 8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend