personal project
words count program
统计文本文件的字符数,单词数和行数。
实现一个统计程序,他能正确的统计程序文件中的字符数,单词数和行数。
源码链接
https://github.com/supipka/wc
心得:
在编写代码时首先考虑到要调佣哪个函数,在循环时是否会增加程序运行时间,在空字符,字符的处理问题上是否计算进去
测试用例
import java.util.Scanner;
public abstract class work{
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
boolean i = true;
int []num = new int[2];
System.out.print( "请输入每回合题目数量:" );
int z = (int)reader.nextInt();
while(i){
int sco = 0;
for(int w=0;w<z;w++){
for(int i1=0;i1<2;i1++)
num[i1] = getnum();
if(getnum()%2==1){
System.out.print( num[0] + "+" + num[1] + "=" );
int h = (int)reader.nextInt();
int j = (int)(num[0]+num[1]);
Printf( j, h );
if (h==j)
sco++;
}
else{
int a=0, b=1;
if(num[0]-num[1]<0){a=1;b=0;}
System.out.print( num[a] + "-" + num[b] + "=" );
int h = (int)reader.nextInt();
int j = (int)(num[a]-num[b]);
Printf( j, h );
if (h==j)
sco++;
}
}
System.out.println("成绩是:" + (int)(((float)sco)/((float)z)*100.0 ));
System.out.println("是否继续:1/0");
int y = reader.nextInt();
if (y==0)
i = false;
}
}
private static int getnum() {
return (int)(Math.random()*10);
}
public static void Printf(int x,int y){
if(x==y)
System.out.println("恭喜你,回答正确!");
else
System.out.println("回答错误,正确答案是:" + " " + x);
}
}