Java应用基础_GPS数据处理

来源:互联网 发布:我的世界商店js制作 编辑:程序博客网 时间:2024/05/21 22:50
package hello;import java.util.Scanner;  public class Demo1 {      public static void main(String[] args) {         Scanner in = new Scanner(System.in);         String s = in.nextLine() ;       int a  ;       boolean ccc = false ;       String h = null,min = null,ss = null ;              for (; !s.equals("END");)       {       if (s.startsWith("$GPRMC"))       {       int loc = s.indexOf("*") ;       String num = s.substring(loc + 1 ) ; //num为校验值       s = s.substring(1, loc) ;// s为$和*之间的字符串      String[] arr = s.split(",") ; //以","拆分字符串      if ( arr[2].equals("A") )//进而判断是否定位      {//      s = s.replace(",", "") ;              //s = GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,,,A//      char[] p = s[0].toCharArray() ;      a = s.charAt(0) ^ s.charAt(1) ;      for (int j = 2 ; j < s.length() ; j++ )      {      a ^= s.charAt(j)  ;      }      //整个字符串进行^运算之后的a      a %= 65536 ;      int f = Integer.parseInt(num, 16) ;      if (a == f)      {      ccc = true ;      h = s.substring(6, 8) ;      min = s.substring(8, 10) ;      ss = s.substring(10, 12) ;      }      }       }       s = in.nextLine() ;       }       if (ccc)       {       int q = Integer.parseInt(h) ;       if (q > 15 )       {       q = q - 15 ;       }       else       {       q += 8 ;       }       if (q < 10)       {       System.out.print("0"  );       }       System.out.print(q + ":") ;       int w = Integer.parseInt(min) ;       if (w < 10)       {       System.out.print("0"  );       }       System.out.print(w + ":") ;       int e = Integer.parseInt(ss) ;       if (e < 10)       {       System.out.print("0");       }       System.out.print( e ) ;       }           }    }  

原创粉丝点击