请教一下,把下面的String[] s={"a","b","c","d","e","f"}; 变成int[]s={1,2,3,4,5,6};怎么反序,下面代码怎么改,谢谢!String[] s={"a","b","c","d","e","f"}; List<String> list=Arrays.asList(s); Collections.reverse(list); list.toArray(s); for(String str:s) { System.out.print(str+" "); } }
2 回答
已采纳
阿旭_
TA贡献217条经验 获得超353个赞
变数字:str.charAt(0) - 'a' + 1
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Test6 { public static void main(String[] args) { /* * 把下面的String[] s={"a","b","c","d","e","f"}; * * 变成int[]s={1,2,3,4,5,6}; */ String[] s = { "a", "b", "c", "d", "e", "f" }; List<String> list = Arrays.asList(s); Collections.reverse(list); list.toArray(s); for (String str : s) { System.out.print((str.charAt(0) - 'a' + 1) + " "); } } }
添加回答
举报
0/150
提交
取消