在Java中使用Zundoko Getter

概述

我试着在Java中玩Zundoko Getter。

的确 (shí jiā)

示例代码

import java.io.*;
import java.net.*;

public class Main {
    public static void main(String[] args) throws Exception {
        int zunCount = 0;
        while (true) 
        {
            String word = zundoko();
            System.out.print(word);
            System.out.print(" ");
            if (word.equals("ズン")) 
            {
                zunCount++;
            }
            else if (zunCount == 4)
            {
                System.out.print("キ・ヨ・シ!");
                break;
            } 
            else
            {
                zunCount = 0;
            }
        }
    }
    private static String zundoko() throws Exception {
        URL url = new URL("http://ohijs0.paas.jp-e1.cloudn-service.com/zundoko");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        InputStream stream = connection.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "utf8"));
        StringBuilder builder = new StringBuilder();
        String line = "";
        while ((line = reader.readLine()) != null) 
        {
            builder.append(line);
        }
        return builder.toString();   
    }        
}
bannerAds