小编Aza*_*Aza的帖子

为什么我的程序只返回零?

我正在编写夏季课程的代码,所以我不必在学校学习入门技术课程.

public class Family {
   public static void main(String[] args) throws IOException {
      String token = "";
      int counter = 0, boyBoy = 0, boyGirl = 0, girlGirl = 0;
      double ratioBB = 0.0, ratioBG = 0.0, ratioGG = 0.0;

      Scanner inFile = new Scanner(new File("MaleFemale.txt"));
      DecimalFormat df = new DecimalFormat("#.##");

      while (inFile.hasNextLine()) {
         counter++;
         token = inFile.nextLine( );
              if(token.equals("BB")) boyBoy++;
         else if(token.equals("BG") || token.equals("GB")) boyGirl++;
         else girlGirl++;
      }

      ratioBB = (boyBoy / counter) * 100;
      ratioBG = (boyGirl / …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
86
查看次数

在Xcode中导入项目示例

我已将示例源项目下载到downloads目录.但我找不到任何关于如何在Xcode ide中导入这些示例项目的文档,以便我可以构建和运行代码以便快速查找.这些下载的示例项目是否应该构建并通过导入运行可以在Xcode中实现.如果是,那么请请有一个很好的方法来做到这一点.

感谢您..

xcode ios

-1
推荐指数
1
解决办法
8827
查看次数

Java - 不推荐使用的API - DataInputStream.readLine

我的教授.给了我这个TCP/UDP的例子,他说这对他有用.但是当我去编译时,我得到一个弃用的API错误,说readLine不再使用了...

我该如何处理?

码:

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

public class Server{

    static  Socket clientSocket = null;
    static  ServerSocket serverSocket = null;

    // This chat server can accept up to 10 clients' connections

    static  clientThread t[] = new clientThread[10];

    public static void main(String args[]) {

    // The default port

    int port_number=2222;

    if (args.length < 1)
        {
        System.out.println("Usage: java MultiThreadChatServer \n"+
                   "Now using port number="+port_number);
        } else {
        port_number=Integer.valueOf(args[0]).intValue();
        }

        try {
        serverSocket = new ServerSocket(port_number);
        }
        catch (IOException e)
        {System.out.println(e);}

    while(true){
        try …
Run Code Online (Sandbox Code Playgroud)

java udp tcp deprecated

-3
推荐指数
2
解决办法
3387
查看次数

使用匹配方法

下面的内容使得如果它在String文本中找到单词hello和goodbye,它将打印为true.我的问题是:你能把它打印出来吗?如果是这样的话?我想把它打印为"是",因为它反对"真实".

String text = "I said hello, and goodbye." 
System.out.println(text.matches("(?i)^.*\\bhello\\b.*\\bgoodbye\\b.*$"));
Run Code Online (Sandbox Code Playgroud)

java

-3
推荐指数
1
解决办法
42
查看次数

标签 统计

java ×3

deprecated ×1

ios ×1

tcp ×1

udp ×1

xcode ×1