zoukankan      html  css  js  c++  java
  • 第1章 Java IO系统 下

    作业

    编码加密

    package ch0320hw;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.PrintWriter;
    
    public class Encoding {
    
        public static void main(String[] args) {
            PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true);
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("请输入,直到quit结束");
            String line = null;
            char[] ch = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
                    't', 'u', 'v', 'w', 'x', 'y', 'z' };
            char[] ch1 = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
                    'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
            try {
                while (!"quit".equals(line = in.readLine())) {
                    StringBuffer sb = new StringBuffer(line);
                    for (int i = 0; i < sb.length(); i++) {
                        for (int j = 0; j < ch.length; j++) {
    
                            if (sb.charAt(i) == ch[j]) {
                                sb.setCharAt(i, ch[(j + 13) % 26]);
                                break;
                            }
                            if (sb.charAt(i) == ch1[j]) {
                                sb.setCharAt(i, ch1[(j + 13) % 26]);
                                break;
                            }
                        }
                    }
                    System.out.println(sb);
    
                }
                in.close();
                out.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.out.println("结束................");
    
        }
    
    }
  • 相关阅读:
    HDUOJ----3342Legal or Not
    HDUOJ----2647Reward
    hduoj------确定比赛名次
    HDUOJ----1165Eddy's research II
    HDUOJ-----1556Color the ball
    HDUOJ-----2175取(m堆)石子游戏
    HDUOJ---------2255奔小康赚大钱
    HDUOJ------1711Number Sequence
    HDUOJ---1712 ACboy needs your help
    HDUOJ---1867 A + B for you again
  • 原文地址:https://www.cnblogs.com/lujing-newer/p/6591969.html
Copyright © 2011-2022 走看看