-
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 08:26 AM.
-
what error are you getting?
-
It won't even compile actually. I know the array stuff is wrong. My book samples have me all confused.
-
Similar Threads
-
By Gary Nelson in forum .NET
Replies: 277
Last Post: 10-01-2003, 12:00 AM
-
By Steve Cochran in forum .NET
Replies: 8
Last Post: 10-18-2002, 12:10 PM
-
Replies: 15
Last Post: 05-09-2001, 04:40 AM
-
By Brian Leung in forum VB Classic
Replies: 12
Last Post: 06-20-2000, 03:06 PM
-
By Brian Leung in forum VB Classic
Replies: 0
Last Post: 06-20-2000, 09: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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks