Need help with arrays


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Need help with arrays

Threaded View

  1. #1
    Join Date
    Aug 2005
    Posts
    8

    Need help with arrays

    I have an assignment and I am confused by the examples the book gives. I have to: 1. Prompt user for number of tests to be entered
    2. Initialize array to hold number of test scores entered
    3. Main method calls for inputData Method (passing array as argument)
    4. Main Method calls for outputData Method (passing array as arg)

    Here is what I have so far. Don't laugh. I am using samples from the book but am having problems piecing it all together. The book kinda sucks for samples.
    /**
    Java file featuring arrays.

    */
    import java.util.*;
    public class XXX Tests

    //*
    User inputs test scores.
    *//

    {

    public static void main(String[] args)

    do
    {

    System.out.println("Enter Number of Tests Between 1 and 5:");
    int n1;

    Scanner Keyboard = new Scanner)System.in);
    n1 = keyboard.nextInt();
    if ((n1 < 0 ) || (n1 > 5 )
    {
    System.out.println("Invalid number entered, please try again:");
    }
    while ((n1 < 0) || (n1 > 5);

    }
    else
    {

    }
    }




    //Declare new array

    double[] testscores = new double[5];

    int index;
    double sum, average;
    Scanner keyboard = new Scanner(System.in);
    System.out.println("Enter test scores:");
    sum = 0
    for (index = 0; index < 5; index++)
    {

    testscores[index] = keyboard.nextDouble();
    sum = sum + testscores[index];
    }

    average = sum/5;

    System.out.println("The average test score is:");
    {

    System.out.println("Hope this helped!");


    }
    Last edited by isuckatjava; 09-01-2005 at 09:26 AM.

Similar Threads

  1. Control Arrays in VB.NET
    By Gary Nelson in forum .NET
    Replies: 277
    Last Post: 10-01-2003, 01:00 AM
  2. Copy/Duplicate Arrays
    By Steve Cochran in forum .NET
    Replies: 8
    Last Post: 10-18-2002, 01:10 PM
  3. Replies: 15
    Last Post: 05-09-2001, 05:40 AM
  4. VB Arrays and memory allocation
    By Brian Leung in forum VB Classic
    Replies: 12
    Last Post: 06-20-2000, 04:06 PM
  5. VB Arrays and memory allocation
    By Brian Leung in forum VB Classic
    Replies: 0
    Last Post: 06-20-2000, 10:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center