• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help!

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic