Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: What is worng with my code ? Passing parameters through and from an array.

  1. #1
    Junior Member
    Join Date
    Dec 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What is worng with my code ? Passing parameters through and from an array.

    /************************************************** ****************************

    Welcome to GDB Online.
    GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
    C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
    Code, Compile, Run and Debug online from anywhere in world.

    ************************************************** *****************************/
    // 1b - Diving Scores
    import java.util.Scanner;

    public class Main
    {

    public static Double[] create_input(int N)


    {


    //Create an array of size N => number of random numbers to be generated
    Double[] input_array = new Double[N];

    Double b;

    // Scanner myObj2 = new Scanner (System.in); // Create a Scanner object
    // b=myObj2.nextDouble ();





    //generate random numbers and assign to array
    for (int i = 0; i < input_array.length; i++)
    {

    Scanner myObj2 = new Scanner (System.in); // Create a Scanner object
    System.out.println ("Please input the scores");
    Double input_array[i] = myObj2.nextDouble ();

    }
    //return array of random numbers
    return input_array;


    }




    public static void main (String[]args)
    {



    //ArrayList<Double> scores = { 0.0,0.0,0.0,0.0,0.0,0.0,0.0 };

    System.out.println ("Diving Scores Calculator ");

    //divername = input("Please input the name of the diver ?")


    Scanner myObj = new Scanner (System.in); // Create a Scanner object
    System.out.print ("Please input the name of the diver ?");

    String userName = myObj.nextLine (); // Read user input
    //System.out.println("Username is: " + userName);



    Main.java:39: error: ']' expected
    Double input_array[i] = myObj2.nextDouble ();
    ^
    Main.java:39: error: ';' expected
    Double input_array[i] = myObj2.nextDouble ();
    ^



    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: What is worng with my code ? Passing parameters through and from an array.

    The error messages say there is a problem at line 39 in the code.
    Which line is line 39?

    The assignment statement should not include the data type: Double.
    The array should be declared at one place
    and values assigned to it at another:
      DataType[]  theName = new DataType[10];   // declare the array
      ...
      theName[2] = aValue;  //  assign a value to an element of the array

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Passing parameters to an Applet
    By Fabgio in forum Java Applets
    Replies: 3
    Last Post: July 26th, 2013, 05:14 PM
  2. passing parameters from Applet to JSP
    By haythem in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 4th, 2013, 02:06 AM
  3. What is worng in my java code
    By janakaraj in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 1st, 2012, 02:10 PM
  4. Trouble passing array in parameters
    By AngryCrow in forum Collections and Generics
    Replies: 2
    Last Post: September 12th, 2011, 09:49 AM
  5. New to vectors passing parameters
    By osmaavenro in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 30th, 2010, 04:32 PM