Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C++ code to print array using for loop

Print array elements using Do-while in Java

Posted on October 9, 2021

Table of Contents

  • Print array elements using Do-while in Java
    • Code to display array elements
      • Code to print integers of an array using do-while loop – #1
      • Code to print integers of an array using do-while loop – #2
      • Code to print Strings of an array using do-while loop – #1
      • Code to print Strings of an array using do-while loop – #2
      • Code to print Character elements of an array using do-while loop – #1
      • Code to print Character elements of an array using do-while loop – #2

Print array elements using Do-while in Java

In this article, we will discuss the concept of Print array elements using Do-while loop in Java

In this post, we are going to learn how to write a program to  print in an array elements using do-while loop in Java language

Code to display array elements

Code to print integers of an array using do-while loop – #1

In this code, we are going to learn how to display integer  array elements in an array using do-while loop in Java language

Program 1

//Display integer of an array using while loop

class Disp_Array_int_Dowhileloop{
public static void main (String args[]){
int arr[]=new int[]{113,611,119,111,167,118}; 
//declaration and initialization of an array

System.out.println("Display elements of given array");

//do-while loop use to displays the elements by incrementing value of i
int i=0;
do{
System.out.println(arr[i]+" ");
i++;

}while(i<arr.length);
}
}

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

Display elements of given array

113
611
119
111
167
118

 

Code to print integers of an array using do-while loop – #2

In this code, we are going to learn how to display integer  array elements in an array using do-while loop in Java language

Program 2

//Display integer of an array using do-while loop

class Disp_Array_int_Dowhileloop1{
public static void main (String args[]){
int arr[]=new int[6]; 
arr[0]=1120;
arr[1]=1310;
arr[2]=1140;
arr[3]=1510;
arr[4]=1160;
arr[5]=1710;
//declaration and initialization of an array

System.out.println("Display elements of given array");

//do while loop use to displays the elements by incrementing value of i
int i=0; 
do{
System.out.println(arr[i]+" ");
i++;
}while(i<arr.length);
}
}

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

Display elements of given array

1120
1310
1140
1510
1160
1710

 

Code to print Strings of an array using do-while loop – #1

In this code, we are going to learn how to display String  array elements in an array using do-while loop in Java language

Program 1

//Java program to read and print string of an array using do-while

class Disp_Array_of_String_doWhileloop{
public static void main (String args[]){
String str[]=new String[]{"Vietnam","Mexico","Turkey","Iran","France"}; 
//declaration and creation of an array


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

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

Your Strings are:

Vietnam
Mexico
Turkey
Iran
France

 

Code to print Strings of an array using do-while loop – #2

In this code, we are going to learn how to display String  array elements in an array using do-while loop in Java language

Program 2

//Java program to read and print string of an array using do-while

class Disp_Array_of_String_doWhileloop1{
public static void main (String args[]){
String str[]=new String[5];
//diclaration and creation of an array
str[0]="Thailand";
str[1]="Italy";
str[2]="spain";
str[3]="Kenya";
str[4]="Uganda"; 

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

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

Your Strings are:

Thailand
Italy
Spain
Kenya
Uganda

 

Code to print Character elements of an array using do-while loop – #1

In this code, we are going to learn how to display  character array elements in an array using do-while loop in Java language

Program 1

//Print character of an array using do whiloe loop
class Disp_Array_Char_DoWhileloop{
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';
//initailaize index wise
System.out.println("\n characters are:");
int j=0; 
do{
System.out.println(Char[j]);
 j++;	
}while(j<Char.length);
//display all characters
}
}

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

Characters are:

x
Y
z
B
c
F

 

Code to print Character elements of an array using do-while loop – #2

In this code, we are going to learn how to display  character array elements in an array using do-while loop in Java language

Program 2

//Print character of an array using do whiloe loop
class Disp_Array_Char_DoWhileloop1{
public static void main (String args[]){
char Char[]=new char[]{'D','E','F','G','H','I'}; 
//diclaration and creation of character array


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

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

Characters are:

D
E
F
G
H
I


Suggested for you

For loop in Java language

While loop in Java language

Do-while loop in Java language

Operator in Java language

Variable in Java language

Data type in Java language

class and main method in Java

One dimensional array in Java

 

Similar post

Java program to read and display array elements using for loop

Java program to read and display array elements using while loop

Java program to read and display array elements using Do-while loop

C code to take and display array elements using for loop

C code to take and display array elements using while loop

C code to take and display array elements using do-while loop

C++ program to read and display array elements using for loop

C++ program to read and display array elements using while loop

C++ program to read and display array elements using do-while loop

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes