class ArrayDemo3
{
public static void main(String[] args)
{
int[]arr = new int[3];
int[]arr1=new int[]{1,3,5,7};
int []arr2={5,7,9};
for(int x=0; x<arr.length() ; x++)
{
System.out.println("arr["+x+"] = "+arr[x]+";");
}
for(int x=0; x<arr1.length() ; x++)
{
System.out.println("arr1["+x+"] = "+arr1[x]+";");
}
for(int x=0; x<arr2.length() ; x++)
{
System.out.println("arr2["+x+"] = "+arr2[x]+";");
}
}
}
class ArrayTest
{
public static void printArray(int[] arr)
{
System.out.print("[");
for(int x=0; x<arr.length(); x++)
{
if(x!=arr.length()-1)
System.out.print(arr[x]+", ");
else
System.out.println(arr[x]+"]");
}
}
public static void main(String[] args)
{
int[] arr = {4,1,8,7,3,8,2};
printArray(arr);
reverseArray(arr);
printArray(arr);
}
public static void reverseArray(int[] arr)
{
for(int start=0,end=arr.length()-1; start<end; start++,end--)
{
swap(arr,start,end);
}
}
public static void swap(int[] arr,int a,int b)
{
int temp = arr[a];
}
}
|
|