微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我需要更新此Java代码才能在Eclipse上工作

如何解决我需要更新此Java代码才能在Eclipse上工作

我发现了一个可以对字符串进行编码和解码的Java代码,但是它是用较旧的Java编写的,我可以通过什么实现来对其进行更新? 应该使用Queue给我们提供密钥集,并对用户给出的消息进行编码,然后将其解码,所有信息都打印出来。

import jss2.CircularArrayQueue;
public class Codes{
   //-----------------------------------------------------------------
   //  Encode and decode a message using a key of values stored in
   //  a queue.
   //-----------------------------------------------------------------
      public static void main ( String[] args)
      {
      int[] key = {5,12,-3,8,-9,4,10};
      Integer keyvalue;

      String encoded = "",decoded = "";

      String message = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " +
                       "computers are lousy actors.";

      CircularArrayQueue<Integer> keyQueue1 = new CircularArrayQueue<Integer>();
      CircularArrayQueue<Integer> keyQueue2 = new CircularArrayQueue<Integer>();

      // load key queue
      for (int scan=0; scan < key.length; scan++)
      {
         keyQueue1.enqueue (new Integer(key[scan]));
         keyQueue2.enqueue (new Integer(key[scan]));
      }

      // encode message
      for (int scan=0; scan < message.length(); scan++)
      {
         keyvalue = keyQueue1.dequeue();
         encoded += (char) ((int)message.charat(scan) + keyvalue.intValue());
         keyQueue1.enqueue (keyvalue);
      }

      System.out.println ("\n\nEncoded Message:\n\n" + encoded + "\n");

      // decode message
      for (int scan=0; scan < encoded.length(); scan++)
      {
         keyvalue = keyQueue2.dequeue();
         decoded += (char) ((int)encoded.charat(scan) - keyvalue.intValue());
         keyQueue2.enqueue (keyvalue);
      }

      System.out.println ("Decoded Message:\n\n" + decoded+"\n\n");
   }
}

解决方法

您使用keyValue声明了变量Integer,但是必须使用int进行了声明。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。