小编use*_*919的帖子

什么是"if/unless"等等

考虑到Ruby中的所有东西都是一个对象,我们可以打开irb并输入类似的东西4.class"Text".class查看一个对象是哪个类,为什么这样做if.class并且unless.class没有给出返回值?

ruby oop irb

5
推荐指数
1
解决办法
184
查看次数

UVa#494 - 正则表达式[^ a-zA-z] +使用Java分割单词

我正在玩UVa#494,我设法用以下代码解决它:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {    
    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while((line = in.readLine()) != null){
            String words[] = line.split("[^a-zA-z]+");
            int cnt = words.length;
            // for some reason it is counting two words for 234234ddfdfd and words[0] is empty
            if(cnt != 0 && words[0].isEmpty()) cnt--; // ugly fix, if has words and the first is empty, reduce one word
            System.out.println(cnt);
        }
        System.exit(0);
    }
} …
Run Code Online (Sandbox Code Playgroud)

java regex logic

2
推荐指数
1
解决办法
1728
查看次数

标签 统计

irb ×1

java ×1

logic ×1

oop ×1

regex ×1

ruby ×1