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);

 

   }

 

}

 

转载于:https://www.cnblogs.com/supipka/p/4468675.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值