Array
Table of Contents
In this article, we will discuss the concept of Java code to print array elements using while
In this post, we are going to learn how to write a program to print in an array using while loop in Java language
In this code, we are going to learn how to display array elements in an array using while loop in Java language
Program 1
//Display integer of an array using for loop
class Disp_Array_int_whileloop{
public static void main (String args[]){
int arr[]=new int[]{13,61,19,11,67,18};
//diclaration and initialization of an array
System.out.println("Display elements of given array");
//for loop use to displays the elements by incrementing value of i
int i=0;
while(i<arr.length){
System.out.print(arr[i]+" ");
i++;
}
}
}
When the above code is executed, it produces the following result
Display elements of given array 13 61 19 11 67 18
In this code, we are going to learn how to display array elements in an array using while loop in Java language
Program 2
//Display integer of an array using while loop
class Disp_Array_int_whileloop1{
public static void main (String args[]){
int arr[]=new int[6];
arr[0]=120;
arr[1]=130;
arr[2]=140;
arr[3]=150;
arr[4]=160;
arr[5]=170;
//diclaration and initialization of an array
System.out.println("Display elements of given array");
//while loop use to displays the elements by incrementing value of i
int i=0;
while(i<arr.length){
System.out.println(arr[i]+" ");
i++;
}
}
} When the above code is executed, it produces the following result
Display elements of given array 120 130 140 150 160 170
In this code, we are going to learn how to display String array elements in an array using while loop in Java language
Program 1
//Java program to read and print string of an array using while
class Disp_Array_of_String_While1{
public static void main (String args[]){
String str[]=new String[5];
//diclaration and creation of an array
str[0]="Canada";
str[1]="UK";
str[2]="USA";
str[3]="India";
str[4]="UAE";
//input the String input
System.out.println("\nYour strings are:");
int j=0;
while(j<str.length){
System.out.println(str[j]);
j++;
}//display all entered string
}
} When the above code is executed, it produces the following result
Your strings are Canada UK USA India UAE
In this code, we are going to learn how to display String array elements in an array using while loop in Java language
Program 2
//Java program to read and print string of an array using while
class Disp_Array_of_String_While2{
public static void main (String args[]){
String str[]=new String[]{"China","India","Brazil","Japan","Egypt"};
//diclaration and creation of an array
System.out.println("\nYour strings are:");
int j=0;
while(j<str.length){
System.out.println(str[j]);
j++;
}//display all entered string
}
}
When the above code is executed, it produces the following result
Your Strings are: China India Brazil Japan Egypt
In this code, we are going to learn how to display character array elements in an array using while loop in Java language
Program 1
//Print character of an array using while loop
class Disp_Array_Char_Whileloop{
public static void main (String args[]){
char Char[]=new char[6];
//Declaration and creation of character array
Char[0]='X';
Char[1]='Y';
Char[2]='Z';
Char[3]='A';
Char[4]='B';
Char[5]='C';
//initialization of characters index wise
System.out.println("\n characters are:");
int j=0;
while(j<Char.length){
System.out.println(Char[j]);
j++;
}//display all characters
}
} When the above code is executed, it produces the following result
characters are: X Y Z A B C
In this code, we are going to learn how to display character array elements in an array using while loop in Java language
Program 2
//Print character of an array using while loop
class Disp_Array_Char_Whileloop1{
public static void main (String args[]){
char Char[]=new char[]{'K','l','M','n','O','p'};
//Diclaration and creation of character array
//initialization of characters index wise
System.out.println("\n characters are:");
int j=0;
while(j<Char.length){
System.out.println(Char[j]);
j++;
}//display all characters
}
} When the above code is executed, it produces the following result
characters are: K l M n O p
Suggested for you
Similar post
Java program to read and print array elements using for loop
Java program to read and print array elements using while loop
Java program to read and print array elements using Do-while loop
C code to take and print array elements using for loop
C code to take and print array elements using while loop
C code to take and print array elements using do-while loop
C++ program to read and print array elements using for loop
C++ program to read and print array elements using while loop
C++ program to read and print array elements using do-while loop
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.