This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

mr_doer
Greenhorn
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{
var=Integer.parseInt(s);
}
catch(IOException e){}
return var;
}
void meth2(){
try{
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{
for(cntr=0;cntr {
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
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
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
Posts: 3341
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....

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?