public class Main {
public static void main(String[] args) {
int[] intary = { 1,2,3,4};
forDisplay(intary);
foreachDisplay(intary);
}
public static void forDisplay(int[] a){
System.out.println("Display an array using for loop");
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
System.out.println();
}
public static void foreachDisplay(int[] data){
System.out.println("Display an array using for
each loop");
for (int a : data) {
System.out.print(a+ " ");
}
}
}Welcome to the world of Java examples, organized by categories and Java packages. Java examples (Java sample source code) help to understand functionality of various Java classes and methods as well as various programming techniques in a simple way, which is otherwise very hard to learn by reading tutorials or Java API. So start exploring...
Sunday, January 8, 2012
How to use for and foreach loops to display elements of an array.
Subscribe to:
Post Comments (Atom)
How to find the most appropriate Keywords?
🔍 Step 1: Understand Your Business and Audience Define your products, services, or content . Identify your target audien...
-
/* Pause Thread Using Sleep Method Example This Java example shows how to pause currently running thread using sleep method of Jav...
-
/* Java String split example. This Java String split example describes how Java String is split into multiple Java String objects. */ ...
-
// File Name GreetingClient.java import java.net.*; import java.io.*; public class GreetingClient { public static void main(String [] ...
No comments:
Post a Comment