如何存储/保存临时值并进行比较?

时间:2016-07-12 07:54:59

标签: java arrays

DatagramSocket clientSocket = new DatagramSocket(10076);
InetAddress IPAddress = InetAddress.getByName("192.168.100.10");
byte[] sendData = new byte[9];
byte[] receiveData = new byte[9];
String sentence = "VDV2bE1";
sendData = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 10076);
clientSocket.send(sendPacket);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
clientSocket.close();

  UDP strToHex = new UDP();
  String result = new String(receivePacket.getData());
  String hex = strToHex.convertStringToHex(result);  
  String cut = hex.substring(10);

  String A = cut.substring(0, 2);
  String B = cut.substring(2, 4);
  String C = cut.substring(4, 6);
  String D = cut.substring(6, 8);

  int cvA = Integer.parseInt(A);    
  int cvB = Integer.parseInt(B);
  int cvC = Integer.parseInt(C);
  int cvD = Integer.parseInt(D);

  int calcA = (cvA - 30)*16;
  int calcB = (cvB - 30);
  int calcC = (cvC - 30)*16;
  int calcD = (cvD - 30);

  int PassIN = calcA + calcB;
  int PassOUT = calcC + calcD;

  int LPassIN = 0;
  int LPassOUT = 0;
  int tempIN;
  int tempOUT;


  if (LPassIN == 0)
  {
      tempIN = LPassIN + PassIN;
  } else if (LPassIN == PassIN)
  {
      tempIN = LPassIN ;
  } else if (LPassIN != PassIN);
  {
      tempIN = PassIN;
  }

  if (LPassOUT == 0)
  {
      tempOUT = LPassOUT + PassOUT;
  } else if (LPassOUT == PassOUT)
  {
      tempOUT = LPassOUT ;
  } else if (LPassOUT != PassOUT);
  {
      tempOUT = PassOUT;
  }

  System.out.println(tempIN);
  System.out.println(tempOUT);

我正在尝试暂时将PassIN中的值保存/存储到LPassIN 然后我要比较两者,如果它们不同则保存到LPassIN并打印新值,否则打印旧值。

1 个答案:

答案 0 :(得分:0)

这应该有效

if (LPassIN != PassIN);
{
    LPassIN = PassIN;
}
System.out.println(LPassIN);