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