import java.util.Scanner;
public class CharArrayInput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of characters: ");
int n = sc.nextInt();
sc.nextLine(); // Consume the newline left after nextInt()
char[] arr = new char[n];
System.out.println("Enter " + n + " characters:");
String input = sc.nextLine();
// Fill the array
for (int i = 0; i < n; i++) {
arr[i] = input.charAt(i); // assumes input length >= n
}
// Print array
System.out.print("Your char array: ");
for (char c : arr) {
System.out.print(c + " ");
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: