NetEase Cloud Classroom To do the Java Video after the lesson of the note, mainly about the string operation, or very rewarding. The title is: http://mooc.study.163.com/learn/ZJU-1000002014?tid=1000002010#/learn/ojhw?id=1000060003
The first question is mainly about the difference between next () and nextline (): One is to read with a space character, and one to read a line at a time. There is also the way to see the end of a string.
NULL ; Boolean false ; Do { = in.next (); = Word.endswith ("." ); // System.out.print (end?) (word.length () = = 1? "": Word.length ()-1): + ""); } while (!end); * *
View Code
The second problem uses more operations on strings, such as intercepting a character, converting a numeric string to an integer, and how to take the position of the trailing character when there are multiple identical characters.
String line=NULL, hhmmss=NULL; while(! (Line=in.next ()). Equals ("END")){ if(!line.contains ("$GPRMC")) Continue; intval = Integer.parseint (line.substring (Line.indexof ("*") +1), 16); Charn = Line.charat (1); for(inti = 2;i<line.length () -3;i++) {n^=Line.charat (i); } if(n = =val) { intFirstcomma = Line.indexof (', '); intSecondcomma = Line.indexof (', ', firstcomma+1); intThirdcomma = Line.indexof (', ', secondcomma+1); if("A". Equals (Line.substring (secondcomma+1, Thirdcomma))) {HHMMSS=line.substring (Firstcomma + 1, Secondcomma); } if(hhmmss!=NULL) { intH =0,m=0,s=0; H=integer.parseint (hhmmss.substring (0, 1)) +8; H= h>24?h-24: H; M=integer.parseint (hhmmss.substring (2,4)); S= Integer.parseint (Hhmmss.substring (4, 6)); System.out.print ((H>= 10? H: "0" + H) + ":" + (M >= 10?) M: "0" + M) + ":" +(S>= 10? S: "0" +s)); } } }View Code
Java Essay (ii)