Table of Contents
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
Do-while loop in Java language
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