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
    Sep 16, 2018
      ·  Edited: Mar 18, 2020

    2.3 How is x = x+1 possible?

    in Introduction to Java

    A. Introduction

    When programming, you will see an expression like x=x+1 quite often. More similar cases are y=y/4 or z=z*0.125. This is all because " = " has a different meaning in coding. Instead of "equals", it means "assignment". i.e. Assigning the RIGHT hand side of the equation to the LEFT hand side of the equation. In this case, x=x+1 means increasing x by 1 and assigning the value back to x.


    Similarly, y=y/4 means reducing y value to 1 quarter of the original. z=z*0.125 means multiplying original z by 0.125 and assigning the product back to z.


    As a matter of fact, this type of operations are so frequently used, that we have shortcut operators just for the purpose:


    C. Try the following:

    D. Kahoot!


    E. HW


    7 comments
    0
    Davey Yu
    Sep 21, 2018  ·  Edited: Mar 21, 2020

    R2 and R3 have the same problem; it must be mystery == mystery +1 to tie it back to mystery. R1 and R4 seems confusing.



    Looks like I'm back a year later. Welp. Time to do this again.

    0
    danny481
    Sep 21, 2018  ·  Edited: Sep 21, 2018

    mystery can't add by 1, and that's on both 2 and 3... For R1, a and c are constants, and b and d aren't.R1 and R4 is confusing, and I'm scratching my head, Because it shows Error, when I press run.

    0
    yd89782
    Sep 23, 2018

    R2 = 0

    R3 = because you've already defined mystery as a int so you don't have to define it again

    R1 = a and c are constants, they are also integers, b and d are floating-point numbers

    R4 = m * ( √ (1 + v / c) / √ (1 - v / c) - 1) = dm, π * r * r * h = volume, 4 * π * r^3 / 3 = volume, √ (x^2 + y^2) = z

    trjoshi3011
    Sep 23, 2018

    R2=0,

    R3= Mystery has already been defined as an int so there's no need to define it again,

    R4= I couldn't get this one bc it kept showing error all the time,

    R1= a=int, constant. c=int, constant. b=float int. d=float int.

    0
    sfolax6776
    Sep 23, 2018

    We will go through this together in the class today

    0
    yd89782
    Sep 23, 2018

    you can't put R4 into codiva because there are undefined variables


    0
    Davey Yu
    Sep 23, 2018

    https://www.codiva.io/p/8292b7b5-cb8c-4fa0-9612-c86a010732ca

    0
    7 comments

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

    • lol-101dotcom

    ©2020 Legion of Learners