1 PackageMian;2 3 ImportJava.util.Scanner;4 5 Public classMain {6 7 Public Static voidMain (string[] args) {8 //TODO auto-generated Method Stub9Scanner in =NewScanner (system.in);TenString s =NULL, S2 =NULL; One intCak; A intB, UTC; - BooleanFlag =true; - Do { thes =In.next (); - if(S.equals ("END")) {//End Judgment -Flag =false; - } + Else if(S.indexof ("$GPRMC") = = 0) {//1. $GPRMC sentence judgment -Cak = S.charat (S.indexof (1)); + for(inti = 2; I < S.indexof (' * '); ++i) { ACak ^= S.charat (i);//calculate an XOR value at } -Cak%= 65536; - if(Cak = = Integer.parseint (s.substring (S.indexof (' * ') +1), +) && s.indexof (", A,")! =-1) {//determine if the XOR value is correct, and whether it is positioned. -S2 = "" + S;//new string saved in S2 - } - } in} while(flag); -s = s2.substring (1);//get the correct string toUTC = Integer.parseint (s.substring (7, 13));//get UTC Value +B = UTC + 80000;//get the value of GMT -s = ":" + string.valueof (b). substring (string.valueof (b). Length ()-2);//the number of seconds is converted to a string containing the leading thes = ":" + string.valueof (b). substring (string.valueof (b). Length ()-4, string.valueof (b). Length ()-2) + s;//Convert fractions into strings *B/= 10000; $ if(B >= 24) {Panax NotoginsengB-= 24; - } the if(B >= 10) { +s = string.valueof (B) +s; A } the Else if(b < && b >= 0) { +s = "0" + string.valueof (B) +s; - } $ System.out.println (s); $ in.close (); - } - the}
"Java Practice" 6-2.GPS data processing