Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE110 Lecture 06

CSE110 Lecture 06

Principles of Programming with Java
Math class
(202205)

Javier Gonzalez-Sanchez
PRO

May 24, 2017
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. CSE110
    Principles of Programming
    with Java
    Lecture 06:
    Math class
    Javier Gonzalez-Sanchez
    [email protected]
    javiergs.engineering.asu.edu | javiergs.com
    Office Hours: By appointment

    View Slide

  2. Previously

    View Slide

  3. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 3
    + operator
    • If two operands of + are numbers, it performs an
    arithmetic addition.
    • If at least one of operands of + is a string, it performs
    a string concatenation.
    • Examples:
    o 2 + 3 will be 5
    o 2 + “ apples” will be “2 apples”
    o “number ” + 5 will be “number 5”
    o “we have “ + 2 + 3 will be “we have 23”
    o “we have “ + (2 + 3) will be “we have 5”

    View Slide

  4. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 4
    Example

    View Slide

  5. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 5
    Example

    View Slide

  6. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 6
    One more thing

    View Slide

  7. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 7
    One more thing

    View Slide

  8. More Instructions

    View Slide

  9. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 9
    Program
    public class MyProgram {
    }
    public static void first()
    {
    }
    public static void second()
    {
    }
    public static
    void main(String[]args) {
    first();
    System.out.println(“”);
    }
    System.out
    println()
    Java API
    Math
    pow()
    sqrt()

    View Slide

  10. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 10
    Math class
    • The Math class contains various mathematical
    methods.
    • To compute √10
    double x = Math.sqrt(10.0);
    • To compute 25.6
    double ans2 = Math.pow(2.0, 5.6);

    View Slide

  11. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 11
    Math class

    View Slide

  12. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 12
    Examples

    View Slide

  13. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 13
    Program
    public class MyProgram {
    }
    public static void first()
    {
    }
    public static void second()
    {
    }
    public static
    void main(String[]args) {
    first();
    System.out.println(“”);
    }
    System.out
    println()
    Java API
    Math
    pow()
    sqrt()
    public static double PI = 3.141592… ;

    View Slide

  14. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 14
    Homework
    Read Chapter 2

    View Slide

  15. CSE110 - Principles of Programming
    Javier Gonzalez-Sanchez
    [email protected]
    Summer 2022
    Disclaimer. These slides can only be used as study material for the class CSE110 at ASU. They cannot be distributed or used for another purpose.

    View Slide