java - 如何将字符串数组和字符串返回到多重拼写数组?
问题描述
使用下面的 main,创建将给出String[]
结果的方法。请在 main 中编写循环以打印多重拼写的数组。
public static void main(String[] args) {
// Create array here
// use your array to create new array here
String[] multispell = Attack(“your array”, “ball”);
输出:
Cast Fire ball!!!
Cast Ice ball!!!
Cast Earth ball!!!
Cast Lightning ball!!!
Cast Wind ball!!
我的程序:
public class Paper {
public static void main (String args[]) {
String[] kind = new String[5];
String [] multispell = Attack4 ( kind , "ball" );
for (int i = 0 ; i< multispell.length ; i++) {
System.out.println ("Cast " + multispell[i]+ "!!!");
}
}
public static String[] Attack4() {
String [] kind111 = {"Fire", "Ice", "Earth", "Lightning", "Wind"};
return kind111 ;
}
}
解决方案
这是你想要的?
public static void main(String[] args) {
String[] kind = new String[] {
"Fire", "Ice", "Earth", "Lightning", "Wind"
};
String[] multispell = Attack(kind, "ball");
for (int i = 0; i < multispell.length; i++) {
System.out.println("Cast " + multispell[i] + "!!!");
}
}
public static String[] Attack(String[] orig, String attach) {
String[] result = new String[orig.length];
for (int i = 0; i < orig.length; i++) {
result[i] = orig[i] + " " + attach;
}
return result;
}
推荐阅读
- arrays - VBA代码使用数组将公式拖到最后一行
- c# - MSBuildWorkspace OpenProjectAsync 有空文档
- javascript - setState 在反应和传递道具与功能
- c# - DDL 文件仅在调试模式下工作
- php - 请求图像附件时更改 URL - Wordpress
- kotlin - 为什么 kotlin 不允许在辅助构造函数中定义属性或注解?
- javascript - VueJS——在动态生成的下拉列表中处理下拉状态
- javascript - nuxt 生命周期方法在页面导航上捕获页面加载事件
- node.js - 使用 knex.js 进行数据迁移在执行 batchInsert 时出现违反检查约束错误
- powershell - 我需要在脚本 RUN 结束时根据时间戳生成日志文件,并且需要通过 SMTP 发送该日志文件