猿问

请教一下,谢谢!

  请教一下,把下面的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+" ");

          }

         }


朴实
浏览 1322回答 2
2回答

阿旭_

变数字:str.charAt(0) - 'a' + 1import 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) + " "); } } }

Bossen

赞楼上
随时随地看视频慕课网APP

相关分类

Java
我要回答