logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    sfolax6776
    Jul 02, 2018
      ·  Edited: Jan 09, 2020

    2.5 - What are standard functions(methods)?

    in Introduction to Java

    A. Introduction

    If your expressions calculate square roots, power, absolute values etc, you might need standard functions (also called methods, "functions" and "methods" can be used interchangeably). For instance, if we need to calculate square root, we use a standard method Math.sqrt().


    Define three variables, a, b and c. Let a=2, b=-1, c=-21. Please write Java code to solve the values of the express to the left.




    B. Standard methods are provided to us in Java Standard Library. We just use them. Common Math Functions(Methods) in Java are listed here:


    C. Try(HW):

    R4.4, R4.5, E4.4

    3 comments
    0
    mr.ricklu
    Jul 07, 2018

    double a=2;

    double b=-1;

    double c=-21;

    System.out.println((-b + Math.sqrt(b*b - 4*a*c))/(2*a)); //Positive solution

    System.out.println((-b - Math.sqrt(b*b - 4*a*c))/(2*a)); // Negative solution

    //3.5

    //-3.0

    0
    wangernestrdragon
    Jul 08, 2018

    double a=2;

    double b=-1;

    double c=-21;

    double d= Math.pow(b, 2)-4*a*c;

    double x1=-b+Math.sqrt(d);

    double x2=-b-Math.sqrt(d);

    double x=x1/(2*a);

    double x3=x2/(2*a);

    System.out.println(x);

    System.out.println(x3);

    }


    -3.0

    3.5

    0
    tian
    Jul 09, 2018

    class quadraticEquation {

    public static void main() {


    int a=2;

    int b=-1;

    int c=-21;

    System.out.println("x=" + ((-b + Math.sqrt(b*b - 4*a*c))/(2*a)) + " or " + ((-b - Math.sqrt(b*b - 4*a*c))/(2*a)));


    }

    }

    x=3.5 or -3.0

    0
    3 comments

    Questions? Email us at legionoflearners@gmail.com or join our WeChat group!

    • lol-101dotcom

    ©2020 Legion of Learners