|
[SOLVED] Unable to access array defiened in constructor in other methods.
/* taking user i/p for row & column size of an array..
* using constructor to collect the value which i m passing from main method
* i m type casting the i/p taken in main using Scanner class .
* Problem -->> unable to access the stud array in other methods .
*/
import java.io.*;
import java.util.Scanner;
class inuser {
public inuser(int r,int c) {
int stud[][] = new int[r][c];
for(int x=0;x<r;x++) {
for(int y=0;y<c;y++) {
int mul=(x+1)*(y+1);
stud[x][y]=mul;
}
}
} // constructor closed
public void dispaly(int r,int c) {
for(int x=0;x<r;x++) {
for(int y=0;y<c;y++) {
System.out.print("\t"+stud[x][y]);
}
System.out.println("");
}
}
public static void main(String args[]) throws IOException {
System.out.println("enter row value");
Scanner s=new Scanner(System.in);
int r=s.nextInt();
System.out.println("entred value ="+r);
System.out.println("enter Column value");
int c=s.nextInt();
System.out.println("entred value ="+c);
inuser in=new inuser(r,c);
in.display(r,c);
}
}
|