美文网首页
基础知识收纳 2018-10

基础知识收纳 2018-10

作者: II花菜君II | 来源:发表于2018-10-22 23:08 被阅读0次

[编程题] 整数反转
输入:-123
输出:-321

import java.util.Scanner;

public class Main {
    public static void main(String[] funArgs) {
        Scanner in = new Scanner(System.in);
        String args = in.nextLine();
        
        if (args == null || args.length() == 0) {
            System.out.print("input not format = "+args);
            return;
        }
 
        int num = 0;
        try {
            num = Integer.parseInt(args);
        } catch(Exception e) {
            System.out.print("input not number = "+e.toString());
            return;
        }
        
        if (num == 0) {
            System.out.print(0);
            return;
        }
        String sig = num >= 0 ? "" : "-";
        String numS = "";
        for(int i = (args.length() - 1); i >= (num > 0 ? 0 : 1); i--) {
            numS += args.charAt(i);
        }
        numS = numS.replaceAll("^(0+)", "");
        
        System.out.print(sig+numS);
    }
}
  • Scanner获取用户输入。另外获取用户输入的方式还有JOptionPane.showInputDialog、new BufferedReader(new InputStreamReader(System.in));
  • length与size。数组使用length。字符串使用length()。
  • 替换0使用replaceAll。正则表达式 ^ 代表开始。+则匹配重复1次或更多次。\d代表数字。\d{5,12}代表5到12位数字。[0-9]与\d同意思。[^aeiou]代表除aeiou之外的字符。

用时50分钟,正则表达式记忆模糊,函数名记忆模糊,误以为funArgs为用户输入。

linux 打包
错误写法:
tar -zcvf tomcat.tar.gz --exclude=tomcat/logs/ --exclude=tomcat/libs/ tomcat

正确写法:
tar -zcvf tomcat.tar.gz --exclude=tomcat/logs --exclude=tomcat/libs tomcat

注意不能加/。

查看本目录下各文件大小
du -h --max-depth=1

android上查看目录各文件大小
du -h -d 1

相关文章

网友评论

      本文标题:基础知识收纳 2018-10

      本文链接:https://www.haomeiwen.com/subject/ltwnzftx.html