Thursday, December 4, 2014

how to invoke an array method from another class








this is the problem







Write a Java project with two different classes. First class named Lab11main should contain only the main() method and the second class named Lab11 should contain a method named int[] reverseArray(int array)which will receive an array from main() method in Lab11main class and then reverse the whole array and should return the reversed array to the main() to print out.







this is what I did







my main class












Java Code:











package java4;
import java.util.Scanner;

public class Lab11main {


public static void main(String[] args){

int i=0;
int [] b;

Scanner input= new Scanner(System.in);
int [] a= new int [10];
a[i]=input.nextInt();


Lab11 ob= new Lab11();
b[i]=ob.reversArray(a);




}







}













Java Code:











package java4;

public class Lab11 {

public int[] reverseArray(int[] a){
int right;
for (int left=0; right=a.length, left<right;i++)
{
int temp= a[left];
a[left]= a[right];
a [right]=temp;
return [] a;

}
}




}
















No comments:

Post a Comment