Res_java练习题讲解(国外英文资料).docVIP

  • 5
  • 0
  • 约1.02万字
  • 约 26页
  • 2017-06-05 发布于河南
  • 举报
Res_java练习题讲解(国外英文资料)

Res_java练习题讲解 9 weeks experiment: 1. The program fills in and does not change the statements associated with the input output. Continuously enter a number of characters that end with # (no Spaces). Statistics and output the length of each string. The output of the output is system.out.println (len); Example: the parenthesis is the explanation Input: Hello_12 # ABC + 0 # (serial2 characters hello_12 and ABC + 0) Output: The length of hello_12 is 8. The length of ABC plus 0 is 5. Code: Import the Java. Util. Scanner; Public class Test60021 { Public static void main (String [] args) @ SuppressWarnings ( unused ) Int len, count, I, k; @ SuppressWarnings ( unused ) Char ch; String STR. Scanner in = new Scanner. STR = in nextLine (); * * * * * * * * * * * Len = 0; Count = 0; For (I = 0; I STR. Length (); I + +) { If (STR. CharAt (I)! = #) { Len++; } The else { System. The out. Println (len); Len = 0; } } } } 2. The program fills in and does not change the statements associated with the input output. Enter a character, ch, first. Then enter a positive integer n (0 n 10), and do the following operations n times: Enter a string, find the character (ch) in the string, and output if found The last location of the character in the string (starting at 0); Otherwise output Not Found. Example: the parenthesis is the explanation Input: M (enter a character) 3 (enter 3 lines of string) moon programming 1234 Output: 0 (m in moon, where the last position is 0) 7 (m in programming) Not Found ( 1234 ) Code: Import the Java. Util. Scanner; Public class Test60023 { Public static void main (String [] args) Int index, I, n, j. Char ch; String STR. Scanner in = new Scanner. () (in).nextline ()).charat (0) - 0; For (I = 1; I = n; I + +) { STR = in nextLine (); The index = 1; For (j = 0; j STR. Length (); j + +) { If (STR. CharAt (j) = = ch) { The index = j; } } If (index = 0) system.out.println (index); The other System is Not Found. } } } 3. The program fills in and does not change the

文档评论(0)

1亿VIP精品文档

相关文档