java中如何把 输入的单词转化为数组来保存数据
- 提问者网友:美人性情
- 2021-04-05 18:07
- 五星知识达人网友:神的生死簿
- 2021-04-05 18:34
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.next();
System.out.println(str.toCharArray());//转换成字符数组
int array[] = new int[str.length()];
for (int i = 0; i < str.length(); i++) {
array[i] = str.charAt(i);
}
for (int i = 0; i < str.length(); i++)
System.out.println(array[i]);
}
}
- 1楼网友:毛毛
- 2021-04-05 21:13
- 2楼网友:掌灯师
- 2021-04-05 19:42
package s1java.xmal1;
public class map { int[] map = new int[100]; //对战地图 int[] luckyturn = {6, 23, 40, 55, 69, 83}; //幸运轮盘 int[] landmine = {5, 13, 17, 33, 38, 50, 64, 80, 94}; //地雷位置 int[] pause = {9, 27, 60, 93}; //暂停 int[] timetunnel = {20, 25, 45, 63, 72, 88, 90}; //时空隧道 public void createmap(){ int i = 0; //在对战地图上设置幸运轮盘 for(i = 0; i < luckyturn.length; i++){ map[luckyturn[i]] = 1; } //在对战地图上设置地雷 for(i = 0; i < landmine.length; i++){ map[landmine[i]] = 2; } //在对战地图上设置暂停 for(i = 0; i < pause.length; i++){ map[pause[i]] = 3; } //在对战地图上设置时空隧道 for(i = 0; i < timetunnel.length; i++){ map[timetunnel[i]] = 4; } } public string getgraph(int i, int index, int playerpos1, int playerpos2){ string graph = ""; if(index == playerpos1 && index== playerpos2){ graph = "@@"; }else if(index == playerpos1){ //graph = "♀"; graph = "a"; }else if(index == playerpos2){ //graph = "♂"; graph = "b"; }else{ switch(i){ case 1: //幸运轮盘 graph = "¤"; break; case 2: //地雷 graph = "★"; break; case 3: //暂停 graph = "■"; break; case 4: //时光隧道 graph = "〓"; break; default: graph = "∷"; break; } } return graph; } public void showline1(int start, int end, int playerpos1, int playerpos2){ for(int i = start; i < end; i++){ system.out.print(getgraph(map[i], i, playerpos1, playerpos2)); } } public void showline2(int start, int end, int playerpos1, int playerpos2){ for(int i = end-1; i >= start; i-- ){ system.out.print(getgraph(map[i], i,playerpos1, playerpos2)); } } public void showrline(int start, int end, int playerpos1, int playerpos2){ for(int i = start; i< end; i++){ for(int j = 28; j > 0; j--){ //输出29个空格 system.out.print(" "); } system.out.print(getgraph(map[i], i,playerpos1, playerpos2)); system.out.println(); } }
public void showlline(int start, int end, int playerpos1, int playerpos2){ for(int i = start; i < end; i++){ system.out.println(getgraph(map[i], i,playerpos1, playerpos2)); } } public void showmap(int playerpos1, int playerpos2){ showline1(0, 31, playerpos1, playerpos2); //显示地图第一行 system.out.println(); //换行 showrline(31,35, playerpos1, playerpos2); //显示地图右竖行 showline2(35, 66, playerpos1, playerpos2); //显示地图第二行 system.out.println(); //换行 showlline(66, 69, playerpos1, playerpos2); //显示地图左竖行 showline2(69, 100, playerpos1, playerpos2); //显示地图第3行 } }
正方形一边上任一点到这个正方形两条对角线的 |
阴历怎么看 ? |