设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索

今天布置的作业好难~

查看数: 2210 | 评论数: 9 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2015-8-20 18:05

正文摘要:

偶的JAVA学得一团糟,考试总是刚及格……

回复

grayuncle 发表于 2015-8-21 13:23:25
99年用QB写过工资管理系统。转行后现在只会让一个字符在屏幕上乱跳

点评

转行?天啊~难道继续写程序不好么?  发表于 2015-8-21 14:32
上贺茂润 发表于 2015-8-21 10:01:22
楼主6的不行

点评

很棒的意思  发表于 2015-8-21 12:23
啊咧?润叔叔确定不是在说偶9?  发表于 2015-8-21 12:14
楼上才6的不行……  发表于 2015-8-21 10:52
冷峻逸 发表于 2015-8-21 09:17:41
提示: 作者被禁止或删除 内容自动屏蔽
RyanBern 发表于 2015-8-20 21:37:51
本帖最后由 RyanBern 于 2015-8-21 09:54 编辑

瞎写玩玩,长时间不用Java,不太熟练。
JAVA 代码复制
  1. class Student{
  2.     private String stuNo = "";
  3.     private String stuName = "";
  4.     public Student(String no, String name){
  5.         this.stuNo = no;
  6.         this.stuName = name;
  7.     }
  8.     public String getStuNo(){
  9.         return stuNo;
  10.     }
  11.     public void setStuNo(stuNo){
  12.         this.stuNo = stuNo;
  13.     }
  14.     public String getStuName(){
  15.         return stuName;
  16.     }
  17.     public void setStuName(name){
  18.         this.stuName = name;
  19.     }
  20.     public String toString(){
  21.         return "姓名:" + stuName + " " + "学号:" + stuNo;
  22.     }
  23.     public boolean equals(Object obj){
  24.         if(!(obj instanceof String)) return false;
  25.         Student stu = (Student)obj;
  26.         return stuNo.equals(stu.getStuNo());
  27.     }
  28. }


JAVA 代码复制
  1. import java.io.*;
  2. public class DateConvert{
  3.     public static void main(String[] args){
  4.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  5.         String input = br.readline();
  6.         int first_index = input.indexOf('/');
  7.         int last_index = input.lastIndexOf('/');
  8.         if(first_index < 0 || last_index == first_index){
  9.             System.out.println("无效的日期格式");
  10.             return;
  11.         }
  12.         String month = input.substring(0, first_index - 1);
  13.         String day = input.substring(first_index + 1, last_index - 1);
  14.         String year = input.substring(last_index + 1);
  15.         System.out.println(year + "年" + month + "月" + day + "日")
  16.     }
  17. }

只写了方法,main方法调用过程自己补上。
JAVA 代码复制
  1. public class StringCounter{
  2.     public static void main(String[] args){}
  3.     public static void countLettersAndNumbers(String str){
  4.         int letter_count = 0, number_count = 0;
  5.         char ch = NULL;
  6.         for(int i = 0;i < str.length();i++){
  7.             ch = str.charAt(i);
  8.             if(ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') letter_count += 1;
  9.             if(ch >= '0' && ch <= '9') number_count += 1;
  10.         }
  11.         System.out.println("字母数:" + letter_count);
  12.         System.out.println("数字数:" + number_count);
  13.     }
  14. }

这个能稍微简单点,但是效率差,有效率高的版本这里没写:
JAVA 代码复制
  1. String str = "测试字符串";
  2. int counts = str.split("朋友").length();

借助正则表达式:
JAVA 代码复制
  1. //需要import java.util.regex;
  2. String str = "测试字符串";
  3. String output = str;
  4. String[] words_to_filter = {"敏感词1", "敏感词2"};
  5. for(int i = 0;i < words_to_filter.length();i++){
  6.     String word = words_to_filter[i];
  7.     output = output.replaceAll(word, "**");
  8. }

点评

再说小朋友你这样,写JS不得撞墙去啊,还搞什么Web!  发表于 2015-9-13 00:25
花括号多好看那,那个说“恶心”的小朋友!不加分号根本就感觉少了些什么有木有!!  发表于 2015-9-13 00:24
我一直很讨厌看到别人把左花括号缩在前一行(埃及花括号),然而在类Java语言中似乎已经成为规矩了……  发表于 2015-8-29 17:08
习惯就好,记得我有一阵天天撸c++代码,看着那么多花括号分号硬是没吐  发表于 2015-8-21 18:51
看见花括弧就恶心啊 虽然Java也是看过 就是不喜欢 ORZ【同样的还有分号  发表于 2015-8-21 18:33

评分

参与人数 1星屑 +20 收起 理由
stevenrock + 20 认可答案

查看全部评分

鑫の尘埃 发表于 2015-8-20 20:23:20
w完全只能看这各位大触们聊了

点评

看楼下,貌似是正确答案呢。一起学。  发表于 2015-8-21 12:18
墨凌羽 发表于 2015-8-20 19:40:56
本帖最后由 墨凌羽 于 2015-8-20 14:03 编辑
taroxd 发表于 2015-8-20 13:23
Ruby 真简单,看了楼主的「提示」就坚决不想学 Java 了


对了 Struct和
RUBY 代码复制
  1. class Student
  2.   attr_reader :stuNo
  3.   attr_reader :name
  4.   def initialize(stuNo, name)
  5.     @stuNo = stuNo
  6.     @name = name
  7.   end
  8. end

这种定义的区别在什么地方
嗯 另外一种鬼畜写法:
RUBY 代码复制
  1. class Student < Hash
  2.         def method_missing(m, *args, &block)
  3.                 return self.has_key?(m) ? self[m] : super
  4.         end
  5. end
  6.  
  7. a = Student[:stuNo,1,:name,"td"]

点评

对  发表于 2015-8-21 07:28
噗 OpenStruct内部也是hash吧 而且也同样黑了method_missing 囧  发表于 2015-8-21 07:04
Student = Class.new(OpenStruct)  发表于 2015-8-21 06:59
都是大神啊~可惜都不是Java语言写得  发表于 2015-8-20 20:20
果然就是提供方便么。。。  发表于 2015-8-20 20:03
taroxd 发表于 2015-8-20 19:23:58
本帖最后由 taroxd 于 2015-8-20 19:29 编辑
墨凌羽 发表于 2015-8-20 18:44
想起折腾ruby 差不多有一个月的时间再折腾字符串处理之类的【csv读取、xml读取、括弧匹配什么的 ...


Ruby 真简单,看了楼主的「提示」就坚决不想学 Java 了

RUBY 代码复制
  1. Student = Struct.new(:stuNo, :name) do
  2.   def equals(others)
  3.     self.stuNo == others.stuNo
  4.   end
  5.  
  6.   def toString
  7.     "姓名:#{name}\t学号:#{stuNo}"
  8.   end
  9. end
  10.  
  11. month, day, year = gets.split('/')
  12. "#{year}年#{month}月#{day}日", year, month, day
  13.  
  14. "随机字符串".count 'A-z'
  15. "随机字符串".count '0-9'
  16.  
  17. "一段歌词".scan('朋友').size
  18.  
  19. "有敏感词的内容".gsub Regexp.union('敏感词', '内容'), ''

点评

听说Java是在C的基础上提高了。  发表于 2015-8-20 23:23
Java效率是C的1/2,嗯  发表于 2015-8-20 21:22
噗 实际上真搞字符串的时间并不多,只不过那一系列都是由此而起罢了【嗯中途元编程、词法分析、语法分析、抽象语法树什么的一堆鬼玩意ORZ  发表于 2015-8-20 19:27
墨凌羽 发表于 2015-8-20 18:44:28
想起折腾ruby 差不多有一个月的时间再折腾字符串处理之类的【csv读取、xml读取、括弧匹配什么的
永恒の未知数 发表于 2015-8-20 18:15:47
虽然我也不会,但我总觉得这是属于例题里面一类的
拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-7-19 15:37

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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