zoukankan      html  css  js  c++  java
  • 代码统计

    测试代码

    package first;
    import java.util.Arrays;
    import java.util.Scanner;
    /*
    //sdfsd
    */
    //sdfsd
    //
    
    public class Test {
        private static int pduan1(String x) {
            if (x.equals("sort1"))
                return 1;
            else if (x.equals("sort2"))
                return 2;
            else
                return 0;
        }
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String[] str = new String[100];
            String t;
            int d;
            int[] b = new int[100];
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            for (int i = 0; i < n; i++) {
                str[i] = in.next();
            }
            for (int i = 0; i < n; i++) {
                b[i] = Integer.parseInt(String.valueOf(str[i].substring(6, 14)));
            }
            for (int i = 0; i < n - 1; i++) {
                for (int j = 0; j < n - 1 - i; j++) {
                    if (b[j] > b[j + 1]) {
                        t = str[j];
                        str[j] = str[j + 1];
                        str[j + 1] = t;
                        d = b[j];
                        b[j] = b[j + 1];
                        b[j + 1] = b[j];
                    }
                }
            }
            in.nextLine();
            while (true) {
                String x = in.next();
                int a = pduan1(x);
                switch (a) {
                case 1:
                    for (int i = 0; i < n; i++) {
                        System.out.println(str[i].substring(6, 10) + "-"
                                + str[i].substring(10, 12) + "-"
                                + str[i].substring(12, 14));
                    }
                    break;
                case 2:
                    for (int i = 0; i < n; i++) {
                        System.out.println(str[i]);
                    }
                    break;
                default:
                    System.out.println("exit");
                    break;
                }
                if (a == 0) break;
            }
        }
    }
    

    源程序

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.Scanner;
    
    public class Main {
    	
    	public static void main(String[] args) throws FileNotFoundException {
    		int whiteLines = 0, commentLines = 0, normalLines = 0;
    		boolean isCommet = false;
    		Scanner scanner = new Scanner(new File(args[0]));//可在命令行里面输入
    		while (scanner.hasNextLine()) {
    			String string = scanner.nextLine();
    			if (string.trim().length() == 0) {
    				whiteLines++;
    			} else if (string.startsWith("//")) { //单行注释
    				commentLines++;
    			} else if (string.startsWith("/*")) { //多行注释
    				commentLines++;                   //注释行数先加一
    				if (!string.endsWith("*/")) {     //如果字符串尾不是*/
    					isCommet = true;              //置isComment为true,说明下面还有注释
    				}
    			} else if (isCommet) {
    				commentLines++;                   //isComment为true,则注释行数加一
    				if (string.endsWith("*/")) {      //如果结尾是*/,则isComment为false
    					isCommet = false;
    				}
    			} else {
    				normalLines++;
    			}
    		}
    		
    		System.out.println("The code has " + normalLines + " lines");
    		System.out.println("The whiteline has " + whiteLines + " lines");
    		System.out.println("The comment has " + commentLines + " lines");
    	}
    }
    

  • 相关阅读:
    c++中memset()函数的用法
    not exits用法讲解(以查询选修全部课程的学生为例)
    数据库中冲突可串行化的判断
    如何快速的判断一个数是否是完全平方数
    杭电oj2089c++
    3月7日学习日志
    3月5日 学习日志
    免编译二进制安装mysql5.7
    base64转换为图片以及图片转换为base64码
    Eclipse编辑JS响应慢,复制粘贴卡顿的解决方案
  • 原文地址:https://www.cnblogs.com/ljl36/p/6525352.html
Copyright © 2011-2022 走看看