方法有很多,用api吧,简单一点,我写一下吧!
import java.util.Scanner;
public class ToCharArray
{
private static Scanner sc=new Scanner(System.in);
public static void main(String[] args)
{
System.out.println("\n\t\t==========字符串转数组!==========\n");
init();
}//初始化!
private static void init()
{
for (; ; )
{
print(input().toCharArray());
}
}
//录入!
private static String input()
{
System.out.println("\n=====请随便输入:=====");
String s=sc.next();
return s;
}
//打印!
private static void print(char[] arr)
{
System.out.print("\n=======数组打印=======:\n");
for (int i=0;i{
System.out.print(arr[i]);
}
System.out.print("\n=====================\n");
}
}