Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1093

Re: <identifier> expected error

From "John B. Matthews" <nospam@nospam.invalid>
Newsgroups comp.lang.java.help
Subject Re: <identifier> expected error
Date 2011-09-22 20:54 -0400
Organization The Wasteland
Message-ID <nospam-2711B8.20543122092011@news.aioe.org> (permalink)
References <c4db596b-eb82-4d41-bfd6-372b4037bfca@l2g2000vbn.googlegroups.com>

Show all headers | View raw


In article 
<c4db596b-eb82-4d41-bfd6-372b4037bfca@l2g2000vbn.googlegroups.com>,
 Kathy Walker <kjata1013@gmail.com> wrote:

> Gah. I'm trying to call a method from one class to another. The TA's 
> are overloaded so I got no one, can anyone tell me what's wrong? I've 
> had one java class like a year ago. Kinda rusty. Thanks!
> 
> class NumArrayList implements NumList
> {
>   double [] Numbers = new double[3];
> 
>   public void main(String args[]){
> 
>     Numbers[0] = 100000;
>     Numbers[1] = 20.9;
>     Numbers[2] = 3;
>   }
>   public  void printArray(){
>   for(int i = 0; i<Numbers.length;i++)
>     System.out.print(Numbers[i] + " ");
>   }
> }
> 
> public interface NumList {
>   printArray();
> }

Something like this? The method main() must be static. Initialize your 
instance variable, typically a lower case name, in the NumArrayList 
constructor. For variety, I've implemented  NumList using a for-each 
loop.


public class Main {

    public static void main(String[] args) {
        new NumArrayList().printArray();
    }
}

interface NumList {
    void printArray();
}

class NumArrayList implements NumList {

    double[] numbers = new double[3];

    public NumArrayList() {
        numbers[0] = 100000;
        numbers[1] = 20.9;
        numbers[2] = 3;
    }

    @Override
    public void printArray() {
        for (double d : numbers) {
            System.out.print(d + " ");
        }
    }
}

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

<identifier> expected error Kathy Walker <kjata1013@gmail.com> - 2011-09-22 16:40 -0700
  Re: <identifier> expected error "John B. Matthews" <nospam@nospam.invalid> - 2011-09-22 20:54 -0400
    Re: <identifier> expected error Kathy Walker <kjata1013@gmail.com> - 2011-09-22 18:08 -0700
      Re: <identifier> expected error "John B. Matthews" <nospam@nospam.invalid> - 2011-09-22 21:24 -0400
  Re: <identifier> expected error Lew <lewbloch@gmail.com> - 2011-09-22 17:56 -0700
    Re: <identifier> expected error Kathy Walker <kjata1013@gmail.com> - 2011-09-22 18:09 -0700
  Re: <identifier> expected error Roedy Green <see_website@mindprod.com.invalid> - 2011-09-23 02:30 -0700
  Re: <identifier> expected error Roedy Green <see_website@mindprod.com.invalid> - 2011-09-23 02:32 -0700
    Re: <identifier> expected error Lew <lewbloch@gmail.com> - 2011-09-23 12:10 -0700
      Re: <identifier> expected error Roedy Green <see_website@mindprod.com.invalid> - 2011-09-23 17:10 -0700
        Re: <identifier> expected error Lew <lewbloch@gmail.com> - 2011-09-23 17:56 -0700
          Re: <identifier> expected error Roedy Green <see_website@mindprod.com.invalid> - 2011-09-25 00:13 -0700

csiph-web