Java printf 🖨️

Поделиться
HTML-код
  • Опубликовано: 6 янв 2025

Комментарии • 158

  • @BroCodez
    @BroCodez  4 года назад +117

    public class Main {
    public static void main(String[] args) {
    // printf() = an optional method to control, format, and display text to the console window
    // two arguments = format string + (object/variable/value)
    // % [flags] [precision] [width] [conversion-character]

    boolean myBoolean = true;
    char myChar = '@';
    String myString = "Bro";
    int myInt = 50;
    double myDouble = 1000;

    // [conversion-character]
    //System.out.printf("%b",myBoolean);
    //System.out.printf("%c",myChar);
    //System.out.printf("%s",myString);
    //System.out.printf("%d",myInt);
    //System.out.printf("%f",myDouble);

    //[width]
    // minimum number of characters to be written as output
    //System.out.printf("Hello %10s",myString);

    //[precision]
    // sets number of digits of precision when outputting floating-point values
    //System.out.printf("You have this much money %.1f",myDouble);

    // [flags]
    // adds an effect to output based on the flag added to format specifier
    // - : left-justify
    // + : output a plus ( + ) or minus ( - ) sign for a numeric value
    // 0 : numeric values are zero-padded
    // , : comma grouping separator if numbers > 1000

    //System.out.printf("You have this much money %,f",myDouble);
    }
    }

    • @Manase-q3k
      @Manase-q3k 7 месяцев назад

      Well explained bro thanks am going to smash my test today

    • @OsmowSaïk
      @OsmowSaïk 2 месяца назад

      First of all: Thank you so much for all your content, I'm sure it has helped countless people in their coding endeavours. Keep it up! :)
      Now for a question: why would the coversion-character for integers be named after "decimal", when those are, by definition at least, the "opposite" of integers? :D
      It doesn't take away from the lesson in the least, but it bugs me and perhaps you, or someone else, find the time to explain or just agree that it doesn't make sense.
      PS: I think you mixed up [precision] and [width] in the order, at least it worked this way when i experimented with the formatting :D
      // % [flags] [width] [precision] [conversion-character]

  • @aerobiesizer3968
    @aerobiesizer3968 2 года назад +32

    This taught me printf better in 11 minutes than my college professor or textbook did in 3 months. Thank you

    • @nickgavrilis2079
      @nickgavrilis2079 Год назад +1

      Dude same! Why do professors overly complicate java so much

    • @andiuptown1711
      @andiuptown1711 Год назад

      @@nickgavrilis2079Learning I/O streams 😢

  • @TuxTuxedo-oc9kg
    @TuxTuxedo-oc9kg Год назад +74

    I think I know all of your java videos lol. Thanks a lot.
    A note I wanted to add for other viewers:
    printf does not automatically go to the next line, similar to System.out.print();
    for that, include a "
    " in the printf statement like this:
    Example:
    double aDouble = 5.5555;
    System.out.printf("%.1f
    ", aDouble);
    this prints the value "5.5" and goes to the next line just like System.out.println(5.5); would do.
    I state this because if you printf twice in a row with double or float values and do not include the "
    " then you may go crazy looking for the error because you will get something like this:
    Example:
    double a = 5.1211
    double b = 4.4511
    System.out.printf("%.2f", a);
    System.out.printf("%.2f", b);
    The output would be:
    5.124.45
    since there is no "
    " included, 4.45 will simply be appended to 5.12 -> 5.124.45
    adding "
    " prevents this from happening:
    System.out.printf("%.2f
    ", a);
    System.out.printf("%.2f
    ", b);
    output:
    5.12
    4.45
    Cheers

  • @thechrome1893
    @thechrome1893 3 года назад +107

    I can't imagine myself learning this all alone. you are making the work smoother for me. good effort bro, keep it up!

  • @harshithakeshav1199
    @harshithakeshav1199 3 года назад +12

    This video helped me understand the printf() method better. Thank you. Keep up the good work !!

  • @paolobonsignore2813
    @paolobonsignore2813 3 года назад +22

    you're even better than any of my professors at college.

  • @FiratC.
    @FiratC. Месяц назад

    I couldnt learn this from my professor in 1 month but i can learn from bro code in 11 minutes!
    THANKS A LOT!!!

  • @nova3227
    @nova3227 3 года назад +5

    Thanks brocode, you are going to be helpful to a lot of software engineers

  • @official-DRFRE
    @official-DRFRE 2 года назад +2

    I love the way you explain everything it's quick precise and clear.... I love it!

  • @flipped-tortoise
    @flipped-tortoise 3 года назад +2

    tbh didnt need this info rn, but after watching a few of your vids your explanations are very clear and precise! thats a sub for me

  • @jazimjazz6928
    @jazimjazz6928 4 года назад +78

    System.out.println(" 100% Better than paid online classes");

    • @sauv1k
      @sauv1k 3 года назад +13

      System.out.printf("%d Better than Paid Online Classes!", 100);

    • @elionayzuridasilveira4140
      @elionayzuridasilveira4140 8 месяцев назад +4

      boolean thisStatement = true;

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 Год назад

    This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro

  • @omersond4891
    @omersond4891 3 года назад

    you are one of the best java teacher

  • @KAnshu-m9z
    @KAnshu-m9z 10 дней назад

    wonderful explanation💛💛💛💛

  • @dianamilenaarchilacordoba4632
    @dianamilenaarchilacordoba4632 4 месяца назад

    great video!!! I'm infinitely grateful for your dedication and big heart to share this knowledge with the world. Thank you soo much

  • @eragondrache6891
    @eragondrache6891 5 месяцев назад

    Good Turotial

  • @Snowmanver2
    @Snowmanver2 3 года назад

    Great video

  • @ardcodelover
    @ardcodelover 2 года назад

    Very nice sir

  • @spooky_zn6
    @spooky_zn6 8 месяцев назад

    great work bro

  • @Joshua_t_
    @Joshua_t_ 2 года назад

    nicely explained

  • @bacon5481
    @bacon5481 2 года назад

    Amazing video, so easy to follow, goated bro.

  • @BakchodMaafia
    @BakchodMaafia 2 года назад

    i really appreciate your assistance brother .God bless you

  • @JuliHoffman
    @JuliHoffman 2 года назад

    This would have helped me earlier this week! Need to watch more videos.

  • @moham129
    @moham129 2 года назад

    Thank for the amazing video

  • @mohammadreza1414
    @mohammadreza1414 6 месяцев назад

    Considering how much headache you have saved us from, you are definitely going to heaven.

  • @anuragsen3694
    @anuragsen3694 3 года назад

    your videos are very helpfull

  • @percivalgebashe4376
    @percivalgebashe4376 Год назад

    Nice

  • @BakhtimurodPrimov
    @BakhtimurodPrimov Год назад

    can't believe such good resources are available for free

  • @jancsovicsmark3409
    @jancsovicsmark3409 2 года назад

    Bro, I'm very appreciative of your help.

  • @ashutoshswain4050
    @ashutoshswain4050 2 года назад

    awesome teaching brother :)

  • @mohamedelfadli3125
    @mohamedelfadli3125 Год назад

    Thanks for the great effort.

  • @ImranPanhwar-kf3rt
    @ImranPanhwar-kf3rt Год назад

    nice

  • @miladysperez2043
    @miladysperez2043 Год назад

    dude i was having such a hard time understanding thank you so much !

  • @anandomia3161
    @anandomia3161 3 года назад

    Awesome

  • @soumelee5661
    @soumelee5661 2 года назад

    good topic. i had no idea, printf exists in java too

  • @aadityapanchal8551
    @aadityapanchal8551 Год назад

    Thanks sir

  • @seanvinluan7562
    @seanvinluan7562 2 года назад

    Yow bro, thank for this tutorials men. It means a lot to me I learned a lot from your videos men, KEEP IT UP BRO!!

  • @IndianSportsTv_4_U
    @IndianSportsTv_4_U Год назад

    very godd videos sir open your branch in india

  • @pa-305
    @pa-305 3 года назад

    best bro

  • @danny.3036
    @danny.3036 3 года назад +1

    Thanks, Bro! ☕ You're awesome!

  • @dimitrie17
    @dimitrie17 4 года назад

    Great explanation! Keep it up!

  • @huuloc8719
    @huuloc8719 3 года назад

    NIce.

  • @UmeshKumar-zh8wk
    @UmeshKumar-zh8wk 3 года назад

    Osm Bro 🔥🔥🔥 Thank U

  • @dannyblanco8544
    @dannyblanco8544 2 года назад

    I just really want to thank you😭! I needed to make my float to only have 4 decimals

  • @automanautomation9845
    @automanautomation9845 3 года назад

    Thank you man, very clear video.

  • @sailorsaturn4693
    @sailorsaturn4693 Год назад

    Thanks King

  • @zarrinnahid448
    @zarrinnahid448 2 года назад

    Damn! You are soo good :0

  • @shivambajpai3368
    @shivambajpai3368 2 года назад

    Thanks so much man, really helped me

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 года назад

    Thanks

  • @曾毓哲-b1t
    @曾毓哲-b1t Год назад

    thank you very much

  • @vanessasantiago2666
    @vanessasantiago2666 2 года назад

    This is so very helpful! Thank you so much!

  • @imsometimesahaterlol
    @imsometimesahaterlol 3 года назад

    Honestly, better than my teacher

  • @matinmonshizadeh
    @matinmonshizadeh 3 года назад

    thanks bro

  • @mukandeinc
    @mukandeinc 2 года назад

    Thanks so much bro

  • @w3jd4n
    @w3jd4n Год назад

    weirdly enough, in my courses' labs we needed formatting yet we've never been taught it

  • @fernandocamarena5634
    @fernandocamarena5634 4 месяца назад

    i was looking exactly for this
    i thought id have to use your c tutorial

  • @pranayprasoon35
    @pranayprasoon35 2 года назад

    Thank bro

  • @faintedkid6745
    @faintedkid6745 2 года назад

    thank you, i was struggling earlier

  • @wolanus
    @wolanus 4 года назад

    Great video!

  • @janajanhajsu4998
    @janajanhajsu4998 Год назад

    Bro is a pro

  • @TranLinh-iy9zy
    @TranLinh-iy9zy Год назад

    Thank you so much ❤

  • @leticiamartinezgarcia1267
    @leticiamartinezgarcia1267 3 года назад

    You saved my day

  • @wewonbro1620
    @wewonbro1620 4 года назад +2

    Bro Code really do be feeling like my Bro for code

  • @PoorwayTraning
    @PoorwayTraning Год назад

    thanks

  • @TheEvertonDias
    @TheEvertonDias 2 года назад

    Thanks, Bro!

  • @misterwiggles8771
    @misterwiggles8771 2 года назад

    Why does he not explain the "%020f" part for when you do a lower number than 20? For me it started with 3 zeros at "%015f" then added zeros up to 8 at 20. I don't know if it's really that important in the grand scheme of things, but it definitely through me for a loop trying to understand that part.

  • @rico.levitt7
    @rico.levitt7 3 года назад

    thank you bro :)

  • @zainrajab648
    @zainrajab648 Год назад +2

    Whenever I write printf and print int with a phrase using %d it doesn't work.
    It works only with char and String, not with number: double, float, int.
    Can anyone tell me what to do?

    • @spacebarium
      @spacebarium Год назад +1

      Showing example code would be helpful

  • @minhtetpaing1695
    @minhtetpaing1695 3 года назад

    Thank you sir.

  • @muskastanikzai1708
    @muskastanikzai1708 2 года назад

    love u bro

  • @fei4009
    @fei4009 Год назад

    thank you so much!!

  • @bekturasanbekov1979
    @bekturasanbekov1979 Год назад

    thx 4 vid bro !

  • @TWVVermin
    @TWVVermin 2 года назад

    thank you,.

  • @aripasternak3305
    @aripasternak3305 Год назад

    thx bro

  • @ghoggaliabdou4222
    @ghoggaliabdou4222 3 года назад

    Thank you.

  • @sairos4057
    @sairos4057 2 года назад

    thanks bro!

  • @fredericoamigo
    @fredericoamigo 2 года назад

    So… kind of like a f-string in python. Nice Bro!

  • @Supertramp133
    @Supertramp133 3 года назад

    Thank you!

  • @chaithdridi2718
    @chaithdridi2718 4 года назад

    You are doing an amazing job Bro 😍

  • @kaiiemsawat3859
    @kaiiemsawat3859 3 года назад +2

    Thank you, Bro
    I wonder how do I do if I want to add .2 as precision and 20 in width in the same time. It doesn't work when I tried it.

    • @heyou1158
      @heyou1158 3 года назад

      % [flags] [width] [precision] [conversion-character]
      i think that is the right sequence because I had the same question. So:
      double myDouble = 1000;
      System.out.printf("%,20.2f",myDouble);
      //that should do the trick

  • @Olivia-t5q1j
    @Olivia-t5q1j 18 дней назад

    why didnt i know about printf sooner?
    i thought only print and println existed in java😭

  • @V_Smah
    @V_Smah 3 года назад

    thanks a lot!!!

  • @revolutionaryfrog
    @revolutionaryfrog 2 года назад

    so this just makes it so i dont have to create and import DecimalFormat DF = new DecimalFormat for double outputs, i should just use printf for any formatting?

  • @aiueo8962
    @aiueo8962 Год назад

    gg bang

  • @sriramn1809
    @sriramn1809 3 года назад

    Is there a way to set the [width] in the string formatting to a variable that can be input from the user?

  • @abdulbasit0123
    @abdulbasit0123 3 года назад

    thanks bro🤍

  • @greeneggsandmushrooms9855
    @greeneggsandmushrooms9855 3 года назад

    was this for matt?

  • @ctluwua7695
    @ctluwua7695 3 года назад +3

    When I Watch his videos I Always Think , When I'll be An Software Engineer , I'll Give 50% Credit to BRO 'Cause He helped me a Lot .
    Much Better than my Damn school.

  • @zukisamaliwa7668
    @zukisamaliwa7668 3 года назад

    How do you put a zero in front of an integer?

  • @alialhussain4139
    @alialhussain4139 7 месяцев назад

    Thanks, Bro 06/03/2024

  • @augischadiegils.5109
    @augischadiegils.5109 4 года назад

    Thanks!!

  • @nikitassouvatzis1928
    @nikitassouvatzis1928 2 года назад

    Η συγκεκριμένη μέθοδος printf() υπάρχει και στη γλώσσα προγραμματισμού C.

  • @maksimush1928
    @maksimush1928 4 года назад

    Hi from Ukraine!! U cool man

  • @mohamedibrahimhassan291
    @mohamedibrahimhassan291 Месяц назад

    This printf() is from C language with the %d, %f ans %s.

  • @beckhamwilson2112
    @beckhamwilson2112 Год назад

    woooo code

  • @lilhose2597
    @lilhose2597 Год назад

    W

  • @shalajko
    @shalajko 4 года назад +1

    some food for the allmighty algorithm : "great , concise, high quality, .addrandomAdjective(); "

  • @anjapietralla5767
    @anjapietralla5767 11 месяцев назад

    😀

  • @straightcable1836
    @straightcable1836 2 года назад

    Can i ask why it's not working on me?

  • @medjl6083
    @medjl6083 4 года назад +1

    formatting method