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

Program to display array value using for loop in Java

Posted on October 9, 2021

Table of Contents

  • Program to display array value using for loop in Java
    • Code to print  array elements
      • Code to print elements of an array using for loop – #1
      • Code to print elements of an array using for loop – #2
      • Code to print Strings of an array using for loop – #1
      • Code to print Strings of an array using for loop – #2
      • Code to print character of an array using for loop – #1
      • Code to print character of an array using for loop – #2
    • Related

Program to display array value using for loop in Java

In this article, we will discuss the concept of Program to display array value using for loop in Java

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

Code to print  array elements

Code to print elements of an array using for loop – #1

In this code, we are going to learn how to display array elements in an array using for loop in Java language

Program 1

//Display integer of an array using for loop

class Disp_Array_element_int{
public static void main (String args[]){
int arr[]=new int[]{3,6,9,12,15,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
for(int i=0; i<arr.length; i++){
System.out.print(arr[i]+" ");

}
}
}

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

Display elements of given array
3,6,9,12,15,18

 

Code to print elements of an array using for loop – #2

In this code, we are going to learn how to display array elements in an array using for loop in Java language

Program 2

//Display integer of an array using for loop

class Disp_Array_element_int1{
public static void main (String args[]){
int arr[]=new int[6]; 
arr[0]=12;
arr[1]=13;
arr[2]=14;
arr[3]=15;
arr[4]=16;
arr[5]=17;
//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
for(int i=0; i<arr.length; i++){
System.out.print(arr[i]+" ");

}
}
}

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

Display elements of given array
12,13,14,15,16,17

 

Code to print Strings of an array using for loop – #1

In this code, we are going to learn how to display string array elements in an array using for loop in Java language

Program 1

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

class Disp_Array_of_String_forloop{
public static void main (String args[]){
String str[]=new String[5]; 
//diclaration and creation of an array

str[0]="Malala";
str[1]="Poma";
str[2]="Neha";
str[3]="Sona";
str[4]="Monika";
//input the String input

System.out.println("\nYour strings are:");

for(int j=0; j<str.length;  j++){
System.out.println(str[j]);	

}//display all entered string
}
}

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

Your Strings are

Malala
Poma
Neha
Sona
Monika

 

 

Code to print Strings of an array using for loop – #2

In this code, we are going to learn how to display string array elements in an array using for loop in Java language

Program 2

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

class Disp_Array_of_String_forloop1{
public static void main (String args[]){
String str[]=new String[]{"Joe","Kumu","Nelo","Puni","Sri"}; 
//diclaration and creation of an array


System.out.println("\nYour strings are:");

for(int j=0; j<str.length;  j++){
System.out.println(str[j]);	

}//display all entered string
}
}

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

Your Strings are

Joe
Kumu
Nelo
Puni
Sri


Code to print character of an array using for loop – #1

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

Program 1

//Print character of an array using for looop
class Disp_Array_Char_Forloop{
public static void main (String args[]){
char Char[]=new char[6]; 
//diclaration and creation of character array
Char[0]='A';
Char[1]='C';
Char[2]='E';
Char[3]='G';
Char[4]='I';
Char[5]='K';

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
C
E
G
I
K

 

Code to print character of an array using for loop – #2

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

Program 2

//Print character of an array using for looop
class Disp_Array_Char_Forloop1{
public static void main (String args[]){
char Char[]=new char[]{'A','D','G','J','M'}; 
//diclaration and creation of character array

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
D
G
J
M

 

Suggested for you

For 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 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

 

 

 

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes