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 6 of 6

Thread: Java Arrays problems with method invetir Not compile

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Java Arrays problems with method invetir Not compile

    Here is my code:

    class ManejadorDeArreglos{
       int b;
       double temporero;
     
      ManejadorDeArreglos(double[] a)
      {
      }
     
    void invertir(double listadodevalores[]){
            for (int i = 0; i < listadodevalores.length/2; i++) 
               {
                   temporero = listadodevalores[i];
                   listadodevalores[i] = listadodevalores[listadodevalores.length-1-i];
                   listadodevalores[listadodevalores.length-1-i] = temporero;
               }
     
               for (int i = 0; i < listadodevalores.length; i++)
               System.out.print("arreglo[" + i + "]" + listadodevalores[i] + "\n");
           //    System.out.print("\n\n");
       }
    }
     
    public class ArraysProgram
    {
       public static void main(String[] args)
       {
          double[] arreglo = {1,3,5,2,4};
          ManejadorDeArreglos miArreglo = new ManejadorDeArreglos(arreglo);
     
          System.out.println("Arreglo original\n" + miArreglo);
          miArreglo.invertir();
          System.out.println("Arreglo invertido\n" + miArreglo);
       }
    }


    Here the fail when compile:

    SamuelRiosP1.java:65: error: method invertir in class ManejadorDeArreglos cannot be applied to given types;
    miArreglo.invertir();
    ^
    required: double[]
    found: no arguments
    reason: actual and formal argument lists differ in length
    1 error

    Let me know whats wrong... thanks

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,316
    Thanks
    53
    Thanked 2,391 Times in 2,345 Posts

    Default Re: Java Arrays problems with method invetir Not compile

    SamuelRiosP1.java:65: error: method invertir in class ManejadorDeArreglos cannot be applied to given types;
    miArreglo.invertir();
    ^
    required: double[]
    found: no arguments
    reason: actual and formal argument lists differ in length
    The compiler found that the source code call to the method on line 65 did not have any arguments,
    but the method requires a double array as an argument.

    Change the call to the method to pass it a double array.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2018
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Java Arrays problems with method invetir Not compile

    Thanks Norm
    Not sure what you means... change the line 65?
    I changed to : double[] miArreglo.invertir();
    but receive this error:
    SamuelRiosP1.java:63: error: ';' expected
    double[] miArreglo.invertir();
    ^
    1 error

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,316
    Thanks
    53
    Thanked 2,391 Times in 2,345 Posts

    Default Re: Java Arrays problems with method invetir Not compile

    To pass an argument to a method means to place the argument inside of the ()s following the method name:
       theMethod(the arguments go here);

    From your program:
      System.out.println("Arreglo original\n" + miArreglo);
    That code passes a String argument to the println method. The String is between the ()s
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2018
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Java Arrays problems with method invetir Not compile

    Thanks Norm,
    Now its working, i like this forum because you only post some tips and we can learn and not the whole answer without explanation like other forums..
    Thank you!

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,316
    Thanks
    53
    Thanked 2,391 Times in 2,345 Posts

    Default Re: Java Arrays problems with method invetir Not compile

    You are welcome.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Arrays not compile
    By term204 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 5th, 2018, 07:54 PM
  2. Method to solve a word search in Java using 2d arrays
    By Kimmi in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 17th, 2013, 09:13 PM
  3. Can't compile classes due to exception problems
    By coltson in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 8th, 2013, 02:22 AM
  4. Java Class : How do I set up a toString method for arrays?
    By red7 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: May 11th, 2012, 05:47 PM
  5. [SOLVED] I'm having problems with removing arrays
    By seaofFire in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 23rd, 2012, 11:18 AM