- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to fill an array of characters from user input
For user input, use the Scanner class with System.in. After getting the input, convert it to character array −
char[] a = s.next().toCharArray();
Now, display it until the length of the character array i.e. number of elements input by the user −
for (int i = 0; i < a.length; i++) { System.out.println(a[i]); }
To fill an array of characters from user input, use Scanner class.
Example
import java.util.Scanner; public class Demo { public static void main(String args[]) { Scanner s = new Scanner(System.in); System.out.println("First add some characters..."); char[] a = s.next().toCharArray(); System.out.println("Elements = "); for (int i = 0; i < a.length; i++) System.out.println(a[i]); } }
Now, enter some input −
RSTUVWXYZ
After entering, you need to run the program to get the following output −
Output
First add some characters... Elements entered = R S T U V W X Y Z
- Related Articles
- Java Program to Get Input from the User
- Java Program to Print Swastika By Taking Input from User
- How to populate an array one value at a time by taking input from user in Java?
- Swift Program to Get Input from the User
- C++ Program to Get Input from the User
- Haskell program to get input from the user
- Java Program to fill elements in an int array
- Java Program to fill an array with random numbers
- How to create input Pop-Ups (Dialog) and get input from user in Java?
- Java program to accept an integer from user and print it
- Java Program to get the Characters in a String as an Array of Bytes
- How to input multiple values from user in one line in Java?
- Can we read from JOptionPane by requesting input from user in Java?
- Java Program to copy an array from the specified source array
- Java Program to Remove Duplicates from an Array List

Advertisements