aspose file tools*
The moose likes Beginning Java and the fly likes Kindly help me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Kindly help me" Watch "Kindly help me" New topic
Author

Kindly help me

mr_doer
Greenhorn

Joined: Dec 05, 2000
Posts: 9
In this program I wanna have the numbers array(numbers[]) in the
arraySplit method.How can I access it.This code is giving an error stating "cannot resolve variable numbers[] in the arrayCount method".If I declare numbers[] outside the meth3,it is
giving array out of bound exception during runtime.Kindly help.

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<num;cntr++)>
{
s2[cntr]=br2.readLine();
numbers[cntr]=Integer.parseInt(s2[cntr]);

}
System.out.println("You entered the following numbers:");
for(int i=0;i<num;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
Eric Spery
Greenhorn

Joined: Nov 19, 2000
Posts: 5
Mr. Doer. The Class file you included has a number of other bugs preventing examination of the specific problem you mention. Did you accidentally post an older version of the file? Is there any way you can post a version which will produce the error you're seeing.
e.
mr_doer
Greenhorn

Joined: Dec 05, 2000
Posts: 9
It is the program, I am battling from two days.The source code is correct but in the decription instead of arrayCount,I mentioned arraySplit.
Thanks,
Sujay
Eric Spery
Greenhorn

Joined: Nov 19, 2000
Posts: 5
Right. I understand the source code you're compiling is working fine with the exception of the error you are discussing; however, the source code you have pasted into your note has other errors as well. I suspect something happened when you cut and paste this code into your mail. Could you repaste the code?
e.
mr_doer
Greenhorn

Joined: Dec 05, 2000
Posts: 9

import java.io.*;
import java.lang.*;
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<num;cntr++)>
{
s2[cntr]=br2.readLine();
numbers[cntr]=Integer.parseInt(s2[cntr]);

}
System.out.println("You entered the following numbers:");
for(int i=0;i<num;i++)>
{
System.out.println(numbers[i]);
}
}
catch(IOException e){}

}
void power(){
flag=1;
this.var=var;
for(int i=1;i<=var;i++)
{
flag=2*flag;
}
}
void arrayCount(){
int i=0;
System.out.println("flag/2="+(flag/2));
for(int cntr=0;cntr<(flag/2);cntr++)
{

if(numbers[cntr]<(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();
obj.power();
obj.arrayCount();
}
}

Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
mr_doer,
Your contribution to Javaranch is very important to us.
However we do have a naming policy outlined here.
Please register again with a name which complies to this rule.
Otherwise I'm afraid you may come to the Ranch soon and find that your account has been locked.
Thank You.


Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Kindly help me
 
Similar Threads
File Comaprison
Please help!
compare two text files
Two Dimensional array declaration in Java
could someone explain the basics from below attached code