what is happening in this code?
Hi, I am new to java
What is happening in this snippet of code?
public name()//Constructor
{
chars=0;
caps=0;
lowercase=0;
gaps=0;
feqnum=newint [5];//is this some sort of an array?
feqnum[0]=0;
feqnum[1]=0;
feqnum[2]=0;
feqnum[3]=0;
feqnum[4]=0;
}
[557 byte] By [
andy2672a] at [2007-11-27 2:27:44]

yes, it's some sort of array. an array of ints, no less. the following statements are superfluous, though. it's already initialized to be full of zeros. and it would be easier to do it in a loop anyway
It is from a program I am trying to understand
public class name{
//Data Members
private int chars;
private int caps;
private int lowercase;
private int gaps;
private long totcha;
private int []freqnum;
public name()//Constructor
{
chars=0;
caps=0;
lowercase=0;
gaps=0;
feqnum=new int [5]; //is this some sort of an array?
feqnum[0]=0;
feqnum[1]=0;
feqnum[2]=0;
feqnum[3]=0;
feqnum[4]=0;
}
Message was edited by:
andy2672
assuming there is no other field feqnum that is not quoted in the code it MUST !!!!
the following lines
feqnum=new int [5]; //is this some sort of an array?
feqnum[0]=0;
feqnum[1]=0;
feqnum[2]=0;
feqnum[3]=0;
feqnum[4]=0;
will not compile with the code provided, as feqnum has never been declared !
> assuming there is no other field feqnum that is not
> quoted in the code it MUST !!!!
>
> the following lines
> > feqnum=new int [5]; //is this some sort of an array?
> feqnum[0]=0;
> feqnum[1]=0;
> feqnum[2]=0;
> feqnum[3]=0;
> feqnum[4]=0;
>
> will not compile with the code provided, as feqnum
> has never been declared !
I think his point was that you could change all the references to feqnum to freqnum as well, so you don't have to make freqnum feqnum. You could also change them all to bananaPudding. There are lots of way to fix it!
> assuming there is no other field feqnum that is not
> quoted in the code it MUST !!!!
>
> the following lines
> > feqnum=new int [5]; //is this some sort of an array?
> feqnum[0]=0;
> feqnum[1]=0;
> feqnum[2]=0;
> feqnum[3]=0;
> feqnum[4]=0;
>
> will not compile with the code provided, as feqnum
> has never been declared !
indeed, my mistake. thanks!