小编ran*_*nny的帖子

Java将字符串添加到字符串数组中

您好我一直在尝试添加String一个String[].这是我的,

static String[] ipList = {"127.0.0.1", "173.57.51.111", "69.696.69.69"};
@Override
public void actionPerformed(ActionEvent e) {
    String newIpGet = textfield.getText();
    try {
        for ( int  i = 0; i < Main.ipList.length; i++){
            Main.ipList[i+1] = newIpGet.toString(); // <---- *****
            Main.write(Main.ipList[i]);
        }
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    Main.amountOfIps = Main.amountOfIps + 1;

    System.out.println("Text Entered!");
    System.out.println("There are now " +Main.ipList.length + " Ips.");
    textfield.setVisible(false);

    label.setVisible(true);;
}
Run Code Online (Sandbox Code Playgroud)

但是,我一直在努力,java.lang.ArrayIndexOutOfBoundsException因为它不会让我做任何新String的.如果ipList[]没有很多修改,我无法修改我的声明,我该怎么办?

java arrays string

6
推荐指数
2
解决办法
130
查看次数

Swift 切换字符串返回

你好,我有一个简单的 switch case 语句,它有一个错误“在预期返回‘字符串’的函数中缺少返回”

我只能看到我正在归还所有东西。没有 if 语句,所以它不能是一个缺失的返回。

enum Sign { case rock, paper, scissors }

func detectWinner(player: Sign, bot: Sign) -> String{
    switch player{
    case .rock:
        switch(bot){
        case .rock: return "You Tied"
        case .paper: return "You Lost"
        case .scissors: return "You Won"
        }
    case .paper:
        switch(bot){
            case .rock: return "You Won"
            case .paper: return "You Tied"
            case .scissors: return "You Lost"
        }
    case .scissors:
        switch(bot){
            case .rock: return "You Lost"
            case .paper: return "You Won"
            case .scissors: return "You Tied" …
Run Code Online (Sandbox Code Playgroud)

return switch-statement swift

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

标签 统计

arrays ×1

java ×1

return ×1

string ×1

swift ×1

switch-statement ×1