标签:
1 package mian; 2 3 import java.util.Scanner; 4 5 public class Main { 6 7 public static void main(String[] args) { 8 // TODO Auto-generated method stub 9 Scanner in = new Scanner(System.in); 10 String s = null, s2 = null; 11 int cak; 12 int B, UTC; 13 boolean flag = true; 14 do { 15 s = in.next(); 16 if(s.equals("END")) {//结束判断 17 flag = false; 18 } 19 else if(s.indexOf("$GPRMC") == 0) {//1.$GPRMC语句判断 20 cak = s.charAt(s.indexOf(1)); 21 for(int i = 2; i < s.indexOf(‘*‘); ++i) { 22 cak ^= s.charAt(i);//计算异或值 23 } 24 cak %= 65536; 25 if(cak == Integer.parseInt(s.substring(s.indexOf(‘*‘)+1), 16) && s.indexOf(",A,") != -1) {//判断异或值是否正确,以及与是否定位。 26 s2 = " " + s;//新建字符串保存于s2 27 } 28 } 29 } while(flag); 30 s = s2.substring(1);//得到正确的字符串 31 UTC = Integer.parseInt(s.substring(7, 13));//得到UTC值 32 B = UTC + 80000;//得到北京时间值 33 s = ":" + String.valueOf(B).substring(String.valueOf(B).length()-2);//秒数转化成字符串,此时包含前导 34 s = ":" + String.valueOf(B).substring(String.valueOf(B).length()-4 , String.valueOf(B).length()-2) + s;//分数转化成字符串 35 B /= 10000; 36 if(B >= 24) { 37 B -= 24; 38 } 39 if(B >= 10) { 40 s = String.valueOf(B) + s; 41 } 42 else if(B < 10 && B >= 0) { 43 s = "0" + String.valueOf(B) + s; 44 } 45 System.out.println(s); 46 in.close(); 47 } 48 49 }
标签:
原文地址:http://www.cnblogs.com/bread/p/4234963.html