Array

Print Character array elements in Java

Print Character array elements in Java

In this tutorial, we will discuss the concept of Print Character array elements in Java

In this topic, we are going to learn how to print character array elements in Java programming language  using loops.

 

In this blog, We have already discuss that “What is an array“, type of arrays and how to access it(one dim, two dim and three dim arrays)

Arrays are the special type of variables to store Multiple type of values(int, string,char, etc)under the same name in the continuous memory location. we can be easily accessed using the indices(indexes)

Here,

  • C, H, A, R  represent the character elements of the array
  • 0,1,2 and 3 represent the index of the array which is used to access the array elements
  • 1,2,3 and 4 represent the length of the array

Display Character array elements in Java

Program to Display Characters of an array in Java using for loop

In this program, we are briefing print character elements of an array using for loop in Java language

Program 1

//Print character of an array using for looop
class Disp_Array_Char_For1{
public static void main (String args[]){
char Char[]=new char[6]; 
//declaration and creation of character array
Char[0]='A';
Char[1]='B';
Char[2]='C';
Char[3]='D';
Char[4]='E';
Char[5]='F';

System.out.println("\n characters are:");
for(int j=0; j<Char.length; j++){
System.out.println(Char[j]); 
}//display all entered characters
}
}

When the above code is executed, it produces the following result

characters are:

A
B
C
D
E
F

 

Program to Display Characters of an array in Java using while loop

In this program, we are briefing print character elements of an array using while loop in Java language

Program 2

//Print character of an array using whiloe loop
class Disp_Array_Char_While1{
public static void main (String args[]){
char Char[]=new char[6]; 
//diclaration and creation of character array
Char[0]='a';
Char[1]='b';
Char[2]='c';
Char[3]='d';
Char[4]='e';
Char[5]='f';

System.out.println("\n characters are:");
int j=0; 
while(j<Char.length){
System.out.println(Char[j]);
 j++; 
}//display all entered characters
}
}

When the above code is executed, it produces the following result

characters are:

a
b
c
d
e
f


Program to Display Characters of an array in Java using do-while loop

In this program, we are briefing print character elements of an array using do- while loop in Java language

Program 3

//Print character of an array using whiloe loop
class Disp_Array_Char_DoWhile1{
public static void main (String args[]){
char Char[]=new char[6]; 
//diclaration and creation of character array
Char[0]='x';
Char[1]='y';
Char[2]='z';
Char[3]='b';
Char[4]='c';
Char[5]='f';

System.out.println("\n characters are:");
int j=0; 
do{
System.out.println(Char[j]);
 j++; 
}while(j<Char.length);
//display all entered characters
}
}

When the above code is executed, it produces the following result

characters are:

x
y
z
b
c
f

 

Suggested for you

for loop in Java

while loop in Java

do-while loop in Java

Single dim array in Java

Data type and variable in Java

Operator in Java

loops in Java language

 

Similar post

Code to read and print integers of an array in Java

Code to read and print strings of an array in Java

Code to read and print characters of an array in Java

Code to read and print integers of an array in C++

Code to read and print strings of an array in C++

Code to read and print characters of an array in C++

Code to read and print integers of an array in C

Code to read and print strings of an array in C

 

 

Program to Display String array elements in Java
Program to create and print an array of string in C
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago