|
-
June 17th, 2011, 10:36 AM
#1
Help adding scanner input to array
Hopefully this will be a simple question. I have to create a program where the user enters 5 values,I add them, average them and state what is above the average. I have created this to a point. I successfully compiled and ran the program using JOptionpane, but because of the output I'd prefer to just put it in the console. My problem is that when I attempt to add the values to the array, it gives me the error:
Unit9.java:29: incompatible types
found : java.lang.String
required: double
myArray[i] = myscanner.next();
I'm not sure why this is doing this. This is the top of my code.
import java.util.Scanner;
public class Unit9
{
public static void main (String [] args)
{
double total, average, round, value;
total = 0;
//create object using Scanner class
Scanner myscanner = new Scanner(System.in);
double []myArray = new double[5];
for(int i=0; i<5;i++)
{
System.out.println("Please enter a value:");
myArray[i] = myscanner.next();
What I'm looking for is why this isn't working. I've used scanner input many times successfully, but it's not working here.
Thanks,
John
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
|
Click Here to Expand Forum to Full Width
|