Java Summary code block

Source: Internet
Author: User

Determine how many times str2 has appeared in STR:
    //Msg////The most painful thing in the world is to have eyes but not to find the ear but not to appreciate the music, the mind but not the truth.//The most painful thing in the world is to miss something that should not be missed, and so on is the one that shouldn't be waiting. The road that should not have gone//The most painful thing in the world is the person you love, he does not love you really love you, but you do not love him do not know whether to choose your love or love you//The msg has several "most painful": Public  static void fun2 () {String msg= "the most painful thing in the world is to have eyes but not to find beauty with ears but not to listen to music and soul. But can not understand what is the most painful thing in the world is to miss the things that should not be missed and so on is not to wait for things to go the road is not supposed to go the most painful thing in the world is the person you love he does not love you really love your people you do not love him do not know the choice you love or love you; int count=0; For (int i = 0;i<msg.length () -3;i++) {String s = msg.substring (i, i+3); if (s.equals ("most painful")) count++;} System.out.println (count); }

Limit the range of random numbers:
        New Random ();                 int New int [Ten];                  for (int i=0;i<arr.length;i++)        {            // limit the range of generated random numbers            arr[i] = r.nextint (221) +2                ; + " ");        }

Java Summary code block

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.