您好我一直在尝试添加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[]没有很多修改,我无法修改我的声明,我该怎么办?
你好,我有一个简单的 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)