main(String[]) exceeds 65535 bytes limit

Asked

Viewed 88 times

-3

  • Do not put in difficult access links, if not to access here, put in own sites for this as Pastebin or ideone

  • 3

    You want to pass over 65k as argument to main ? Certainly doesn’t sound like a good idea. It would be better to read from a file.

1 answer

0

As you have noticed, Java does not allow such long methods:

package ordenar;

import java.util.ArrayList;
import java.util.*;

public class Exercicio{
      public static void main(String [] args){

        double a [] = { <um array grotescamente gigante> };

        ArrayList<Double> valores = new ArrayList<Double>();
        ArrayList<Double> par = new ArrayList<Double>();
        ArrayList<Double> impar = new ArrayList<Double>();
        int par1 =0;
        int impar1 = 0;


        for(int cont = 0; cont<a.length; cont++) {
           valores.add(cont, a[cont]);
       }     

       Collections.sort(valores);

       for(double cont = 0; cont<valores.size(); cont++) {

           double valor = valores.get((int) cont);

           if(valor%2==0) {
               par.add(valor);
               par1++;               
           }else {
               impar.add(valor);
               impar1++;
           }
       }

       System.out.println("impares "+impar1);
       System.out.println("pares " + par1);    
       System.out.println("vetor impar ");

       for (int i = 0; i < impar.size(); i++) { 
           double valor = impar.get(i);
             System.out.print(", " + valor);
        }
       System.out.println(" ");
       System.out.println("vetor par ");

       for (int i = 0; i < par.size(); i++) { 
           double valor = par.get(i);
             System.out.print(", " + valor);
        }       

    }
}

This huge array clearly should not be declared within the program. Data should get saved in files on hard drive, when a program needs them it will have to read the files containing the data.

That is, create any file with these numbers (for example, numeros.txt) and have your Java program open the file and read the numbers from there.

How to read a text file in Java?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.