Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0

    Default Some confusion with arrays

    I am working on an assignment for my class (yes I am permitted to ask for assistance outside of the classroom) the assignment is to write a program that declares an array "alpha" of 50 elements of type "double". Initialize the array so that the first 25 elements are equal to the square of the index variable and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed. So far I have been able to get through most of the code using a test class but am unable to make it work live. My problems come where I print the element of the array, I wind up with a single error "Evaluate_5.java:21: error: cannot find symbol
    System.out.println ( m_array[i] );"

    Java Code:
    import java.util.*;
    
    public class Evaluate_5 
    {
    public static void main(String args[])
    {
    double[] alpha = new double[50];
    //Initialize the first 25 elements of the array (int i=0; i<25; i++)//
    for(int i = 0; i < 25; i++)
    {
    alpha[i]= i * i;
    }
    //Initialize the last 25 elements of the array (i=25; i<50; i++)//
    for(int i = 25; i < 50; i++)
    {
    alpha[i]= 3 * i;
    }
    //Print the element of the array
    System.out.println ( "The values are: " );
    for (int i = 25; i < 50; i++)
    System.out.println ( m_array[i] );
    }
    //Print method to display the element of the array
    void print(double m_array[])
    {
    for(int i =1; i <= m_array.length; i++)
    {
    System.out.print(m_array[i-1] +" ");
    if(i%10==0)
    System.out.print("\n");
    }
    }
    }
    I am not asking for anyone else to write this for me, I want to learn the material but I am asking for a pointer to get me back on track...Thanks

  2. #2
    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0

    Default Re: Some confusion with arrays

    ok so I've got it to compile and run except it is outputting a single value each line.

  3. #3
    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0

    Default Re: Some confusion with arrays

    Java Code:
    import java.util.*;
    
    public class Evaluate_5 
    {
    public static void main(String args[])
    {
    double alpha[] = new double[50];
    //Initialize the first 25 elements of the array (int i=0; i<25; i++)//
    for(int i = 0; i < 25; i++)
    {
    alpha[i]= i * i;
    }
    //Initialize the last 25 elements of the array (i=25; i<50; i++)//
    for(int i = 25; i < 50; i++)
    {
    alpha[i]= 3 * i;
    }
    //Print the element of the array
    System.out.println ( "The values are: " );
    for (int i = 0; i < 50; i++)
    System.out.println ( alpha[i] );
    }
    //Print method to display the element of the array
    void print(double m_array[])
    {
    for(int i =1; i <= m_array.length; i++)
    {
    System.out.print(m_array[i-1] +" ");
    if(i%10==0)
    System.out.print("\n");
    }
    }
    }

Similar Threads

  1. object name confusion
    By mobosecomin in forum New To Java
    Replies: 4
    Last Post: 01-20-2011, 03:45 AM
  2. Confusion here @@' Help!
    By pleasurelyours in forum New To Java
    Replies: 7
    Last Post: 06-09-2010, 04:42 PM
  3. Confusion in line
    By JavaJunkie in forum New To Java
    Replies: 1
    Last Post: 06-13-2009, 11:46 PM
  4. Tic Tac Toe confusion
    By jigglywiggly in forum New To Java
    Replies: 15
    Last Post: 04-12-2009, 02:47 AM
  5. Confusion over arrays
    By dbashby in forum New To Java
    Replies: 5
    Last Post: 04-04-2009, 10:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •