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 10, 2018
      ·  Edited: Jan 14, 2021

    1.8 What is output? What is output formatting? What are escape sequences?

    in Introduction to Java

    A. Introduction:

    How do you know if a program runs correctly or not? You check the results, or the output of the program. Sometimes the output is data, sometimes the output is a pattern like a Christmas tree. When printing out data values, you might want to generate the output in a certain format. For instance, dollar values should always have 2 decimal places, $2 should be $2.00.


    B. System.out.println(), System.out.print() and System.out.printf()

    1. We know System.out.println() prints strings, values of expressions, or both.

    2. System.out.print() is similar, but always prints on the same line

    3. System.out.printf() allows you to "format" the output such as the number of decimal places. For instance, System.out.printf("%.2f", Math.PI) prints Pi value with two decimal places.

    4. How to use System.out.printf() ?

    C. Try:

    1. Did you print out a Christmas tree? Can you print a star on the tree top?

    2. How to print out a dollar amount with leading $ and two decimal places?

    3. How to print out two decimal values that are right aligned? For example,


    4. Write a program that prints an animal speaking a greeting, similar to but different from the following. Notice to print '\', you need to enter '\\'. Learn more about escape sequences here.

     /\_/\     ----- 
    ( ' ' )  / Hello \
    (  -  ) <  Junior |
     | | |   \ Coder!/
    (__|__)    -----
    12 comments
    Davey Yu
    Sep 11, 2018

    If x value changes, v does not, because of the fact that it divides itself after being times by ten. Which means no matter the answer of x, it will end up as ten, and 10-7=3

    sfolax6776
    Sep 11, 2018

    You got it :)

    0
    sfolax6776
    Sep 11, 2018

    Check out this link: https://www.wikihow.com/Read-Someone%27s-Mind-With-Math-(Math-Trick)


    Can you implement more tricks?

    0
    Davey Yu
    Sep 11, 2018

    Yes, you can, and I've already done the math to explain why it works.

    0
    trjoshi3011
    Sep 13, 2018

    If you change the value of x then the value of v does not change, because you are just multiplying x times 10 and then dividing that solution by x to get v which = 3. So, the value of v does not change.

    danny481
    Sep 13, 2018

    Changing the value of x will not change the value of y, and the answer is always 3.

    yd89782
    Sep 15, 2018

    the value of v won't change because you are basically dividing x by itself and then multiplying that by 10.

    kaedeshimizu2015
    Sep 19, 2020

    class Main { public static void main(String[] args) { System.out.println(" /\\_/\\ ----- "); System.out.println("( \' \' ) / Hello \\ "); System.out.println("( - ) < Junior |"); System.out.println(" | | | \\ Coder!/"); System.out.println("(__|__) -----"); } }

    0
    flashepicokc
    Sep 20, 2020

    class Main { public static void main(String[] args) { System.out.println (" /\\_/\\ ----- "); System.out.println ("( ' ' ) / Hello \\"); System.out.println ("( - ) < Junior |"); System.out.println (" | | | \\ Coder!/"); System.out.println ("(__|__) -----"); } }

    0
    brendan.yen
    Sep 26, 2020

    class Brendan { public static void Brendan(String[] args) { System.out.println(" /\\___/\\ _________"); System.out.println(" ( . _ . )< Hello \\"); System.out.println(" ------- | Human |"); System.out.println(" (_) (_) | Programmer|"); System.out.println(" | _ | \\_________/ "); System.out.println(" (_) (_)");

    0
    xunzhu0711
    Oct 03, 2020

    class Main {

    publicstaticvoid main(String[] args) {