aspose file tools*
The moose likes Beginning Java and the fly likes Please help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please help!" Watch "Please help!" New topic
Author

Please help!

mr_doer
Greenhorn

Joined: Dec 05, 2000
Posts: 9
In the arrayCount method, the numbers array is not accessible,I wanna have all the array methods declared in meth3() method to be
in the arrayCount method.How can I get it?
import java.io.*;
class one{
public int num;
int var;
int flag;
int cntr;
int meth1(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
var=Integer.parseInt(s);
}
catch(IOException e){}
return var;
}
void meth2(){
try{
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
String s1=br1.readLine();
num=Integer.parseInt(s1);
}
catch(IOException e){}
}
void meth3(){
System.out.println("num="+num);
int cntr;
String s2[]=new String[num];
int numbers[]=new int[num];
try{
BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));
for(cntr=0;cntr {
s2[cntr]=br2.readLine();
numbers[cntr]=Integer.parseInt(s2[cntr]);
}
System.out.println("You entered the following numbers:");
for(int i=0;i {
System.out.println(numbers[i]);
}
}
catch(IOException e){}
}
int power(int var){
flag=1;
this.var=var;
for(int i=1;i<=var;i++)
{
flag=2*flag;
}
return flag/2;
}
void arrayCount(){
int i=0;
System.out.println("flag/2="+(flag/2));
for(int j=0;j<(flag/2);j++)
{
if(numbers[j]<(flag/2))
i++;
}
System.out.println("value of i="+i);
}
}
class three{
public static void main(String args[]){
one obj=new one();
System.out.println("Enter the type of variable:");
int var=obj.meth1();
System.out.println("Mention the total Numbers to be entered:");
obj.meth2();
System.out.println("Enter the numbers:");
obj.meth3();
int sub_factor=obj.power(var);
System.out.println("Subtraction factor="+sub_factor);
obj.arrayCount();
}
}

Thanks,
Mr.Doer
mr_doer
Greenhorn

Joined: Dec 05, 2000
Posts: 9

NB: Correction(I wanna hava all the array numbers declared in meth3() to be in the arrayCount method.)

In the arrayCount method, the numbers array is not accessible,I wanna have all the array numbers declared in meth3() method to be
in the arrayCount method.How can I get it?
Thanks,
Mr.Doer

B Young
Greenhorn

Joined: Aug 31, 2000
Posts: 6
First a couple of housekeeping issues. Two of your for loops in meth3()are incomplete, example: for(cntr=0;cntr { . I suspect this happened in the cut and paste to the forum. In arrayCount() the numbers[] array has not been declared.
I suspect that your problem is due to local variable names versus class data members. The names of variables that are declared in a method are local to the method. When you use the same variable name in a method as a class data member name you must you the keyword this to refer to the class member.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
mr_doer and B_Young,
please read and follow the Naming Policy. It's to your benefit. We periodically do book give aways to people who post to a forum and as a matter of fact one is being conducted on the Advanced forum now. Only those who meet the naming policy are entered in the contest for the give away so....


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
Don't get me started about those stupid light bulbs.
 
subject: Please help!
 
Similar Threads
File Comaprison
Kindly help me
compare two text files
Two Dimensional array declaration in Java
could someone explain the basics from below attached code