gpt4 book ai didi

java - 分割扫描仪字符串

转载 作者:行者123 更新时间:2023-12-01 11:31:37 25 4
gpt4 key购买 nike

import java.io.IOException;
import java.util.Scanner;


public class web_practice {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub

Scanner scanner = new Scanner(System.in);
String input = scanner.next();

int l = input.indexOf(' ');
String cmd = input.substring(0, l);
String end = input.substring(l);

if (cmd.equals("define"));
java.awt.Desktop.getDesktop().browse(java.net.URI.create("http://dictionary.reference.com/browse/" + end));
}
}

我试图编写一个代码来查找单词的定义,方法是将其连接到dictionary.com并检查他们是否将“定义”一词作为第一个单词?

拆分不起作用。

最佳答案

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub

Scanner scanner = new Scanner(System.in);
String input = scanner.next();

int words[] = input.split(' ');

if (words[0].equalsIgnoreCase("define")) {
java.awt.Desktop.getDesktop().browse(java.net.URI.create("http://dictionary.reference.com/browse/" + words[0]));
}
}

关于java - 分割扫描仪字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30341021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com