java字符数组怎么输入
时间: 2024-06-10 09:08:41 浏览: 53
java从键盘输入数组
要输入Java字符数组,可以使用Scanner类的next()方法。下面是一个示例代码:
import java.util.Scanner;
public class ArrayInput {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
char[] chars = new char;
for (int i = 0; i < 3; i++) {
chars[i] = in.next().charAt(0);
}
System.out.print("输入的字符数组为:");
for (int i = 0; i < 3; i++) {
System.out.print(chars[i] + " ");
}
}
}
阅读全文