鱼C论坛

 找回密码
 立即注册
查看: 8405|回复: 117

[技术交流] #鱼C五周年嘉年华# 《JAVA程序设计&改错》# 第一章

[复制链接]
发表于 2015-1-22 23:59:46 | 显示全部楼层 |阅读模式
活动类型:
线上活动
开始时间:
2015-1-23 00:00 至 2015-2-23 00:00 商定
活动地点:
鱼c论坛
性别:
不限
已报名人数:
13

本帖最后由 百日维新 于 2015-2-25 02:12 编辑

答题注明题号,提交完整的程序

No01:程序设计,写一个程序验证一个整数是否是奇数 (5分)


No02:程序改错,计算1 - 20 的累加 (5分)
public class Test {
public static void main(String args[]){
         short t = 0;
   
         for(int i=0 ;i < 20;i++){
             t =   t + i;
         }
   
         System.out.println(t);
    }

}


No03:程序设计,输出倒立三角形 (5分)


No04:程序改错,输出minutes = 60  (5分)
public class Clock {
    public static void main(String[] args) {
        int minutes = 0;
        
        for(int ms =0; ms < 60*60*1000; ms ++){
            if(ms  %  60*1000 == 0){
                minutes ++;
            }
        }
        System.out.println(" minutes = "+minutes);

    }

}


No05:程序设计,实现字符串反转,例如输入“i love fishc" , "应输出chsif evol i"(5分)


No06:程序改错  (10分)
两数相减,输出0.9
public class DoubleSub {

    public static void main(String[] args) {
            System.out.println(2.0  - 1.1);

    }

}


No07:程序设计,有一个字符串,其中包含中文字符、英文字符和数字字符,请统计和打印出各个字符的个数。(10分)


No08:程序设计,打印字符串长度,"a\u0022.length()+\u0022b" (10分)


No09:程序设计,x = 2014 ,y = 2015,用异或交换x , y的值 (15分)


No10
:程序设计,用最有效率的方法算出2乘以8等於几 (15分)
未完待续。。。




已通过 (13 人)

  留言 申请时间
zhangyu

学习

2015-3-2 22:21
月之吟

来尝试一下~

2015-2-17 10:27
花生

怎么提交啊?就是回帖吗?

2015-2-7 19:28
pridas 2015-2-3 22:09
曾经的肆无忌惮

哎呀呀、点这个才算参加是吗!

2015-1-30 16:19
大黑鱼

来试试

2015-1-28 13:03
wwwxinyu1990

试试做做~

2015-1-24 13:13
青玄

好好好!

2015-1-24 09:39
小龙_h

我也要参加!

2015-1-23 20:29
雪是梅之香 2015-1-23 18:48

评分

参与人数 1荣誉 +3 鱼币 +3 贡献 +1 收起 理由
小龙_h + 3 + 3 + 1 热爱鱼C^_^

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-23 09:58:28 | 显示全部楼层
No01
  1. public static void test(int num){
  2.                 if(num%2==1){
  3.                         System.out.println(num+"是奇数");
  4.                 }else{
  5.                         System.out.println(num+"是偶数");
  6.                 }
  7.         }
复制代码


请问我这样提交对吗,是要交一个完整的程序还是这样就行了

点评

壮士,第二章更新了,速来拿奖!  发表于 2015-1-27 21:40
+0  发表于 2015-1-27 11:14
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-23 10:15:51 | 显示全部楼层
No09
  1. int x=2014,y=2015;
  2.                 x=x^y;
  3.                 y=x^y;
  4.                 x=x^y;
  5.                 System.out.println("x="+x+",y="+y);
复制代码


No10
  1. public static void t(){
  2.                 int num=2<<3;
  3.                 System.out.println(num);
  4.         }
复制代码

点评

我很赞同!: 5.0
我很赞同!: 5
+30分  发表于 2015-1-27 10:17
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-1-23 11:21:53 | 显示全部楼层

最好是提交一个完整的程序,方便判断对错
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-1-23 11:28:32 | 显示全部楼层

你这个有错,在去考虑一下吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-1-23 11:31:56 | 显示全部楼层

No09 :pass
No10 :pass

请再接再厉!:big
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-23 13:37:12 | 显示全部楼层

第一题:
public static void countJS(int n){
  if(n % 2 == 0)
   System.out.println("这是个偶数");
  else
   System.out.println("这是个奇数");
  
}


第二题:
public class Test {
public static void main(String args[]){
          short t = 0;
     
          for(int i=0 ;i <= 20;i++){
              t += i;
          }
     
          System.out.println(t);
     }

}


第三题:
public static void putTrigon(int n){
  for(int i = n;i > 0;i--){
   System.out.print(i);
   for(int x = 0;x < n-i;x++)
    System.out.print(" ");
   for(int j = i * 2 - 1;j > 0;j--){
    System.out.print("*");
   }
   System.out.println();
  }
}
QQ截图20150123124224.png

第四题:
public static void main(String[] args) {
        int minutes = 0;
        
        for(int ms =0; ms < 60*60*1000; ms ++){
            if(ms  %  (60*1000) == 0){
                minutes ++;
            }
        }
        System.out.println(" minutes = "+minutes);
}
第五题:
public static void main(String[] args) {
        String str = "i love fishc";
        netateString(str);
}
public static void netateString(String str){
  char[] c = str.toCharArray();
  for(int i = c.length - 1;i >= 0;i--)
   System.out.print(c);
}
QQ截图20150123125612.png

第六题:
public static void main(String[] args) {
   System.out.print(2.0f-1.1f);
}
第七题:
public static int[] countString(String str){
  int[] c = {0,0,0};
  char[] ca = str.toCharArray();
  for(int i = 0;i < ca.length;i++){
   System.out.println((int)ca);
   if(ca >= 48 && ca <= 57){
    c[0]++;
   }
   else if((ca >= 97 && ca <= 122)||(ca >= 65 && ca <= 90)){
    c[1]++;
   }
   else{
    c[2]++;
   }
  }
  return c;
}
第八题:表示没懂什么意思
第九题:
int x = 2014;
   int y = 2015;
   x = x ^ y;
   y = x ^ y;
   x = x ^ y;
   System.out.println("x = " + x);
   System.out.println("y = " + y);
第十题:
int x = 2;
int y = x << 3;
System.out.println(y);

点评

我错了,原来你一直看不到我说话。。。。第二章更新了,速来拿奖!然后把第一章没对的赶紧做了吧  发表于 2015-1-27 21:38
5 + 5 + 5 +5 + 0 + 10 + 0 + 0 + 15 + 15 分  发表于 2015-1-27 10:32
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-1-23 13:59:55 | 显示全部楼层
hacker.jin 发表于 2015-1-23 13:37
第一题:
public static void countJS(int n){
  if(n % 2 == 0)

这是一个字符串,然后计算它的长度,""里面就是字符串的内容
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-23 14:09:16 | 显示全部楼层
No2
  1. public class Test {
  2. public static void main(String args[]){
  3.          short t = 0;
  4.    
  5.          for(int i=0 ;i < 20;i++){
  6.              t =  (short ) t + i;
  7.          }
  8.    
  9.          System.out.println(t);
  10.     }

  11. }
复制代码

点评

壮士,第二章更新了,速来拿奖!  发表于 2015-1-27 21:41
+ 5分,继续努力  发表于 2015-1-27 10:34
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-23 14:42:44 | 显示全部楼层

回帖奖励 +3 鱼币

                //1
                int a=3,b=4;
                System.out.println((a & 1) != 0);
                System.out.println((b & 1) != 0);
                //2  short int不能+
                int t = 0;
                for(int i=1 ;i < 21;i++){
            t =   t + i;
        }
                //3
                System.out.println("* *\n *");
                //4 运算符优先级 * 先于 % 加括号
        int minutes = 0;
        
        for(int ms =0; ms < 60*60*1000; ms ++){
            if(ms  %  (60*1000) == 0){
                minutes ++;
            }
        }
        System.out.println(" minutes = "+minutes);
        //5
        System.out.println(new StringBuffer("i love fishc").reverse().toString());
        //6 import java.math.BigDecimal;
        System.out.println((new BigDecimal("2.0")).subtract(new BigDecimal("1.1")));
        //7
        String toCount = "四个汉字ninechars02";
        int cn=0,chars=0,num=0;
        for(int i=0;i<toCount.length();i++){
                if(Character.toString(toCount.charAt(i)).matches("^[\u4e00-\u9fa5]{1}$")){cn++;}
                if(Character.isLetter(toCount.charAt(i))) chars++;
            if(Character.isDigit(toCount.charAt(i))) num++;
        }
        System.out.println("; 汉字:"+cn+"; 字母:"+(chars-cn)+"; 数字:"+num);
        //8  "a\u0022.length()+\u0022b" == "1"+"b"
        System.out.println("a\u0022.length()+\u0022b".length());
        //9 异或
        int x=2014,y=2015;
        x^=y; y^=x; x^=y;
        System.out.println(x+" "+y);
        //10 移位运算
        System.out.println(2<<3);

点评

5+5+5+5+5 +10+10+0+15+15  发表于 2015-1-27 10:57
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-1-23 15:11:53 | 显示全部楼层
trulyzhu 发表于 2015-1-23 14:42
//1
                int a=3,b=4;
                System.out.println((a & 1) != 0);

这位鱼同学,要提交完整的程序,就是包含main()函数,方便评分
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-1-23 15:14:28 | 显示全部楼层
trulyzhu 发表于 2015-1-23 14:42
//1
                int a=3,b=4;
                System.out.println((a & 1) != 0);

第八题不是你这个意思,就是要算出引号里面字符串的长度
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-23 16:32:05 | 显示全部楼层
我是python过来帮顶哒~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-1-23 20:24:18 | 显示全部楼层

欢迎:lol:
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-24 11:17:33 | 显示全部楼层
No02
  1. public class Test {
  2.         public static void main(String args[]) {
  3.                 int t = 0;
  4.                 for (int i = 0; i <= 20; i++) {
  5.                         t = t + i;
  6.                 }
  7.                 System.out.println(t);
  8.         }
  9. }
复制代码


No04
  1. public class Clock {
  2.     public static void main(String[] args) {
  3.         int minutes = 0;
  4.         
  5.         for(int ms =0; ms < 60*60*1000; ms ++){
  6.             if(ms  %  (60*1000) == 0){
  7.                 minutes ++;
  8.             }
  9.         }
  10.         System.out.println(" minutes = "+minutes);
  11.     }
  12. }
复制代码

点评

+10分  发表于 2015-1-27 10:48
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-24 11:22:24 | 显示全部楼层
No03
  1. public class te {
  2.     public static void main(String[] args) {
  3.         for(int i=0;i<5;i++){
  4.                 for(int j=i;j<5;j++){
  5.                         System.out.printf("*");
  6.                 }
  7.                 System.out.printf("\n");
  8.         }
  9.     }
  10. }
复制代码

点评

+5分  发表于 2015-1-27 10:49
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-1-24 14:05:49 | 显示全部楼层
hacker.jin 发表于 2015-1-23 13:37
第一题:
public static void countJS(int n){
  if(n % 2 == 0)

第八题是引号里面有一个字符串,然后计算它的长度并打印出来
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-24 14:21:47 | 显示全部楼层
别弄仅作者可见
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-24 14:24:22 | 显示全部楼层
No05
  1. import java.io.*;
  2. public class te {
  3.     public static void main(String[] args) {
  4.             String s;
  5.         BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
  6.         try {
  7.                         s=rd.readLine();
  8.                         for(int i=s.length()-1;i>=0;i--){
  9.                         System.out.printf("%c",s.charAt(i));
  10.                 }
  11.                 } catch (IOException e) {
  12.                         e.printStackTrace();
  13.                 }  
  14.     }


  15. }
复制代码

No06
  1. public class DoubleSub {
  2.     public static void main(String[] args) {
  3.             System.out.printf("%.1f",2.0-1.1);
  4.     }
  5. }
复制代码

点评

+5+10 分  发表于 2015-1-27 10:50
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-1-24 15:18:14 | 显示全部楼层
No08
  1. public class test {
  2.     public static void main(String[] args) {
  3.         System.out.println("a\u0022.length()+\u0022b".length());
  4.     }
  5. }
复制代码
No07
  1. import java.io.*;
  2. import java.util.regex.*;
  3. public class te {
  4.     public static void main(String[] args) {
  5.             String s;
  6.             Pattern p;
  7.             Matcher m;
  8.             p = Pattern.compile("[\u4e00-\u9fa5]");       
  9.             int count1=0,count2=0,count3=0;//count1代表中文字符个数  count2代表英文字符的个数  count3代表数字字符的个数
  10.             System.out.println("请输入字符串:");
  11.         BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
  12.         try {
  13.                         s=rd.readLine();
  14.                         for(int i=0;i<s.length();i++){
  15.                                 char c=s.charAt(i);
  16.                                 m = p.matcher(String.valueOf(c));
  17.                                 if(c>='0'&&c<='9'){
  18.                                         count3++;
  19.                                 }else if((c>='a'&&c<='z')||(c>='A'&&c<='Z')){
  20.                                         count2++;
  21.                                 }else if(m.find()){
  22.                                         count1++;
  23.                                 }
  24.                         }
  25.                         System.out.println(s.length());
  26.                 } catch (IOException e) {
  27.                         e.printStackTrace();
  28.                 }
  29.         System.out.println("中文字符有"+count1+"个,英文字符有"+count2+"个,数字字符有"+count3+"个。");
  30.     }
  31. }
复制代码



点评

0 + 10分  发表于 2015-1-27 10:52
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-19 06:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表