Figure out what is printed to the console












-2















What will be the output of the following code ?



String letters =
{ "laid", "leave", "lean", "ease", "east", "legals", "revo", "fights", "limit", "live" };
int result = Stream.of( letters )
.filter( w -> isVowel( w.charAt( 3 ) ) )
.mapToInt( w -> w.length() )
.filter( w -> w % 2 == 0 )
.sum();
System.out.println(result);









share|improve this question




















  • 5





    Did you try to run it?

    – Eran
    Nov 24 '18 at 16:05











  • Depends on what isVowel does, you didn't include that.

    – Mark
    Nov 24 '18 at 16:06













  • 18=4+6+4+4. ease, legals, revo and live has vowel at index 3 and even length. note that we exclude 'limit' because length is odd.

    – boly38
    Nov 24 '18 at 16:14


















-2















What will be the output of the following code ?



String letters =
{ "laid", "leave", "lean", "ease", "east", "legals", "revo", "fights", "limit", "live" };
int result = Stream.of( letters )
.filter( w -> isVowel( w.charAt( 3 ) ) )
.mapToInt( w -> w.length() )
.filter( w -> w % 2 == 0 )
.sum();
System.out.println(result);









share|improve this question




















  • 5





    Did you try to run it?

    – Eran
    Nov 24 '18 at 16:05











  • Depends on what isVowel does, you didn't include that.

    – Mark
    Nov 24 '18 at 16:06













  • 18=4+6+4+4. ease, legals, revo and live has vowel at index 3 and even length. note that we exclude 'limit' because length is odd.

    – boly38
    Nov 24 '18 at 16:14
















-2












-2








-2








What will be the output of the following code ?



String letters =
{ "laid", "leave", "lean", "ease", "east", "legals", "revo", "fights", "limit", "live" };
int result = Stream.of( letters )
.filter( w -> isVowel( w.charAt( 3 ) ) )
.mapToInt( w -> w.length() )
.filter( w -> w % 2 == 0 )
.sum();
System.out.println(result);









share|improve this question
















What will be the output of the following code ?



String letters =
{ "laid", "leave", "lean", "ease", "east", "legals", "revo", "fights", "limit", "live" };
int result = Stream.of( letters )
.filter( w -> isVowel( w.charAt( 3 ) ) )
.mapToInt( w -> w.length() )
.filter( w -> w % 2 == 0 )
.sum();
System.out.println(result);






java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 21:17









Gayan Mettananda

1,106713




1,106713










asked Nov 24 '18 at 16:04









Anshul MadhanAnshul Madhan

1




1








  • 5





    Did you try to run it?

    – Eran
    Nov 24 '18 at 16:05











  • Depends on what isVowel does, you didn't include that.

    – Mark
    Nov 24 '18 at 16:06













  • 18=4+6+4+4. ease, legals, revo and live has vowel at index 3 and even length. note that we exclude 'limit' because length is odd.

    – boly38
    Nov 24 '18 at 16:14
















  • 5





    Did you try to run it?

    – Eran
    Nov 24 '18 at 16:05











  • Depends on what isVowel does, you didn't include that.

    – Mark
    Nov 24 '18 at 16:06













  • 18=4+6+4+4. ease, legals, revo and live has vowel at index 3 and even length. note that we exclude 'limit' because length is odd.

    – boly38
    Nov 24 '18 at 16:14










5




5





Did you try to run it?

– Eran
Nov 24 '18 at 16:05





Did you try to run it?

– Eran
Nov 24 '18 at 16:05













Depends on what isVowel does, you didn't include that.

– Mark
Nov 24 '18 at 16:06







Depends on what isVowel does, you didn't include that.

– Mark
Nov 24 '18 at 16:06















18=4+6+4+4. ease, legals, revo and live has vowel at index 3 and even length. note that we exclude 'limit' because length is odd.

– boly38
Nov 24 '18 at 16:14







18=4+6+4+4. ease, legals, revo and live has vowel at index 3 and even length. note that we exclude 'limit' because length is odd.

– boly38
Nov 24 '18 at 16:14














2 Answers
2






active

oldest

votes


















1














Here's how to find out the result without running the code:



int result = Stream.of(letters)
.filter(w -> isVowel(w.charAt(3))) // I'm assuming isVowel returns true for vowels (a,e,i,o,u),
// so after this step only the Strings whose 4th character
// (index 3) is a vowel (such as "ease") remain in the
// Stream
.mapToInt(w -> w.length()) // here you transform each remaining String to its length
// (for example "ease" becomes 4)
.filter(w -> w % 2 == 0) // here you keep only the even lengths
.sum(); // finally you sum the remaining lengths


This should be easy enough to calculate.






share|improve this answer































    0














    NB I'm assuming isVowel returns true if the argument is a vowel.



    After executing filter(), you will end up with a list of all strings whose 4th character is a vowel.



    Which means after the filter is applied you'll now have a list of



    ["ease", "legal", "revo", "limit", "live"]



    Now your next instruction (mapToInt) says convert this list of strings to a list of integers. And how do you determine what these integers will be? Their length. The next instructions is saying creating me a list of all the lengths of the remaining strings after filtering. Which means you'll end up with a list of



    [4, 5, 4, 5, 4]



    Now the next operation says can you give me a list of numbers that when divided by 2 the remainder is 0? This is a list of even numbers. So the next result will be



    [4, 4, 4]



    Now the last instruction says, can you sum up the contents of the last evaluated list?



    this is 4*3 = 12.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459948%2ffigure-out-what-is-printed-to-the-console%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Here's how to find out the result without running the code:



      int result = Stream.of(letters)
      .filter(w -> isVowel(w.charAt(3))) // I'm assuming isVowel returns true for vowels (a,e,i,o,u),
      // so after this step only the Strings whose 4th character
      // (index 3) is a vowel (such as "ease") remain in the
      // Stream
      .mapToInt(w -> w.length()) // here you transform each remaining String to its length
      // (for example "ease" becomes 4)
      .filter(w -> w % 2 == 0) // here you keep only the even lengths
      .sum(); // finally you sum the remaining lengths


      This should be easy enough to calculate.






      share|improve this answer




























        1














        Here's how to find out the result without running the code:



        int result = Stream.of(letters)
        .filter(w -> isVowel(w.charAt(3))) // I'm assuming isVowel returns true for vowels (a,e,i,o,u),
        // so after this step only the Strings whose 4th character
        // (index 3) is a vowel (such as "ease") remain in the
        // Stream
        .mapToInt(w -> w.length()) // here you transform each remaining String to its length
        // (for example "ease" becomes 4)
        .filter(w -> w % 2 == 0) // here you keep only the even lengths
        .sum(); // finally you sum the remaining lengths


        This should be easy enough to calculate.






        share|improve this answer


























          1












          1








          1







          Here's how to find out the result without running the code:



          int result = Stream.of(letters)
          .filter(w -> isVowel(w.charAt(3))) // I'm assuming isVowel returns true for vowels (a,e,i,o,u),
          // so after this step only the Strings whose 4th character
          // (index 3) is a vowel (such as "ease") remain in the
          // Stream
          .mapToInt(w -> w.length()) // here you transform each remaining String to its length
          // (for example "ease" becomes 4)
          .filter(w -> w % 2 == 0) // here you keep only the even lengths
          .sum(); // finally you sum the remaining lengths


          This should be easy enough to calculate.






          share|improve this answer













          Here's how to find out the result without running the code:



          int result = Stream.of(letters)
          .filter(w -> isVowel(w.charAt(3))) // I'm assuming isVowel returns true for vowels (a,e,i,o,u),
          // so after this step only the Strings whose 4th character
          // (index 3) is a vowel (such as "ease") remain in the
          // Stream
          .mapToInt(w -> w.length()) // here you transform each remaining String to its length
          // (for example "ease" becomes 4)
          .filter(w -> w % 2 == 0) // here you keep only the even lengths
          .sum(); // finally you sum the remaining lengths


          This should be easy enough to calculate.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 16:10









          EranEran

          287k37467556




          287k37467556

























              0














              NB I'm assuming isVowel returns true if the argument is a vowel.



              After executing filter(), you will end up with a list of all strings whose 4th character is a vowel.



              Which means after the filter is applied you'll now have a list of



              ["ease", "legal", "revo", "limit", "live"]



              Now your next instruction (mapToInt) says convert this list of strings to a list of integers. And how do you determine what these integers will be? Their length. The next instructions is saying creating me a list of all the lengths of the remaining strings after filtering. Which means you'll end up with a list of



              [4, 5, 4, 5, 4]



              Now the next operation says can you give me a list of numbers that when divided by 2 the remainder is 0? This is a list of even numbers. So the next result will be



              [4, 4, 4]



              Now the last instruction says, can you sum up the contents of the last evaluated list?



              this is 4*3 = 12.






              share|improve this answer




























                0














                NB I'm assuming isVowel returns true if the argument is a vowel.



                After executing filter(), you will end up with a list of all strings whose 4th character is a vowel.



                Which means after the filter is applied you'll now have a list of



                ["ease", "legal", "revo", "limit", "live"]



                Now your next instruction (mapToInt) says convert this list of strings to a list of integers. And how do you determine what these integers will be? Their length. The next instructions is saying creating me a list of all the lengths of the remaining strings after filtering. Which means you'll end up with a list of



                [4, 5, 4, 5, 4]



                Now the next operation says can you give me a list of numbers that when divided by 2 the remainder is 0? This is a list of even numbers. So the next result will be



                [4, 4, 4]



                Now the last instruction says, can you sum up the contents of the last evaluated list?



                this is 4*3 = 12.






                share|improve this answer


























                  0












                  0








                  0







                  NB I'm assuming isVowel returns true if the argument is a vowel.



                  After executing filter(), you will end up with a list of all strings whose 4th character is a vowel.



                  Which means after the filter is applied you'll now have a list of



                  ["ease", "legal", "revo", "limit", "live"]



                  Now your next instruction (mapToInt) says convert this list of strings to a list of integers. And how do you determine what these integers will be? Their length. The next instructions is saying creating me a list of all the lengths of the remaining strings after filtering. Which means you'll end up with a list of



                  [4, 5, 4, 5, 4]



                  Now the next operation says can you give me a list of numbers that when divided by 2 the remainder is 0? This is a list of even numbers. So the next result will be



                  [4, 4, 4]



                  Now the last instruction says, can you sum up the contents of the last evaluated list?



                  this is 4*3 = 12.






                  share|improve this answer













                  NB I'm assuming isVowel returns true if the argument is a vowel.



                  After executing filter(), you will end up with a list of all strings whose 4th character is a vowel.



                  Which means after the filter is applied you'll now have a list of



                  ["ease", "legal", "revo", "limit", "live"]



                  Now your next instruction (mapToInt) says convert this list of strings to a list of integers. And how do you determine what these integers will be? Their length. The next instructions is saying creating me a list of all the lengths of the remaining strings after filtering. Which means you'll end up with a list of



                  [4, 5, 4, 5, 4]



                  Now the next operation says can you give me a list of numbers that when divided by 2 the remainder is 0? This is a list of even numbers. So the next result will be



                  [4, 4, 4]



                  Now the last instruction says, can you sum up the contents of the last evaluated list?



                  this is 4*3 = 12.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 24 '18 at 16:39









                  ivange94ivange94

                  4461514




                  4461514






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459948%2ffigure-out-what-is-printed-to-the-console%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Tonle Sap (See)

                      I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

                      Guatemaltekische Davis-Cup-Mannschaft