String str = "A team like a warrior can only seize the opportunity and play three games, but the jazz still can't find a way to deal with the warrior".
1, write code to find the keyword "team", "opportunity" where the string str index position, find the string of the second "warrior" position, and output on the console
2, defines the int variable m, the value of all the index values in the first question and
3, the contents of the output m as char type on the console
4, write code implementation will str string with "," to split the array, and output the value of the index value of 4
5, write code implementation will "jazz" in the STR string instead of "warrior", "Warrior" with "jazz" instead, and output the result to the console (disable replace method)
6. Write code to take a portion of the STR string to print on the console this sentence: Warriors seize the opportunity to find a way to cope
7, write a piece of code, you can take out any QQ e-mail address in the QQ number
8, use for and if to print a hollow square
9, use a For loop to print a diamond
10. Use a For loop to print a hollow diamond (optional title)
Packagecom.test;Importjava.util.Arrays; Public classLianxi { Public Static voidMain (string[] args) {String str= "A team like a warrior can only seize the opportunity if they have a tight defense," + "after three games, Sir, there's no way to fight the warrior."; //"Team", "opportunity"System.out.println (Str.indexof ("Team")); System.out.println (Str.indexof (Opportunity)); System.out.println (Str.lastindexof (Warriors)); intm = Str.indexof ("team") + Str.indexof ("opportunity") + Str.lastindexof ("Warrior")); System.out.println (m); System.out.println ((Char) m); System.out.println (Str.split (",") [4]); String[] Newstr= Str.split (""); String Temp= ""; for(inti = 0; i < newstr.length; i++) { if(Newstr[i].equals ("Yong")) ) {Newstr[i]= "Spyker"; } Else if(Newstr[i].equals ("Viscount")) ) {Newstr[i]= "Yong"; } temp+=Newstr[i]; } System.out.println (temp); //Warriors seize the opportunity to find a way to copeSystem.out.print (Str.substring (Str.indexof ("Warrior"), Str.indexof ("Warrior") +2)); System.out.print (str.substring (Str.indexof ("Seize the opportunity"), Str.indexof ("Seize the opportunity") +4)); System.out.print (str.substring (Str.indexof (","), Str.indexof (",") +1)); System.out.print (str.substring (Str.indexof ("Find a response"), Str.indexof ("Find coping") +4)); System.out.print (str.substring (Str.indexof ("Method"), Str.indexof ("measures") +2)); System.out.println (); String Qqemail= "[Email protected]"; System.out.println (Qqemail.substring (0,qqemail.indexof ("@"))); intn = 4; //print a hollow square for(inti = 0; I < n; i++) { if(i==0| | I==n-1) { for(intj = 0; J < N; J + +) {System.out.print (A); } } Else { for(intj = 0; J < N; J + +) { if(j==0| | J==n-1) {System.out.print (A); } Else{System.out.print (" "); }}} System.out.println (); } System.out.println ("Print Diamond"); //Print Diamond for(inti=0;i<n;i++) { for(intj=0;j<n-1-i;j++) {System.out.print (" "); } for(intk=0;k< (2*i+1); k++) {System.out.print ("*"); } System.out.println (); } for(intq=0;q<n-1;q++) { for(intw=0;w<q+1;w++) {System.out.print (" "); } for(inte=0;e<2*n-3-2*q;e++) {System.out.print ("*"); } System.out.println (); } System.out.println (); //Print Hollow Diamond for(inti=0;i<n;i++) { for(intj=0;j<n-1-i;j++) {System.out.print (" "); } for(intk=0;k< (2*i+1); k++) { if(k==0| | k==2*i) {System.out.print ("*"); } Else{System.out.print (" "); }} System.out.println (); } for(intq=0;q<n-1;q++) { for(intw=0;w<q+1;w++) {System.out.print (" "); } for(inte=0;e<2*n-3-2*q;e++) { if(e==0| | e==2*n-4-2*q) {System.out.print ("*"); } Else{System.out.print (" "); }} System.out.println (); } }}
Perhaps it is hot these days, the fan has not been repaired, the heat of the brain is not good, this part of the problem is still quite strenuous, the idea is not skilled.
The tenth chapter----the Java Loop exercises