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: Mar 16, 2021

    2.1 - What are literals and data types?

    in Introduction to Java

    A. Introduction

    Other than printing out Christmas trees and graphics, System.out.println statement can also do simple calculations such as 3.1415*2*3. Numeric values such as "3.1415", "2" or "2.71828" are frequently used to compute. These numeric values are called "literals". Sometimes literals maybe fractions or power of tens. How would you write fractions or exponents? See if you can figure out from the table below.

    B. Arithmetic equations are made of variables, literals and -- operators

    You always need operators to compute. +, -, * are straight forward. But why 1729/10 = 172? what is 1729%10? See the table below:


    C. Try this:

    1. What will happen if you run the following code?

    class HelloWorld {
      public static void main(String[] args) {
        System.out.print("5+4 is:");
        System.out.println(5+4);
      }
    }

    2. What's the difference between System.out.print("5+4 is:") and System.out.print(5+4 )?


    3. What's the difference between System.out.print("5+4 is:") and System.out.println("5+4 is:")?

    4. How can you print out the values of 15 - 4? 15 x 4 ? 15 ➗4?

    5. What will “System.out.print(5/2);” print out?

    6. How to make sure 15 ➗4 prints correct decimal values in Java?


    7. Explain why 1729%10 is9, why 1729/10 is 172.

    1 comment
    0
    dylanchauhan2007
    Jan 08, 2020

    If you write n%10, it will always print out the last digit of the variable, or n. If you write n/10, it will print out n without the last digit.

    0
    1 comments

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

    • lol-101dotcom

    ©2020 Legion of Learners