main (String []) exceeds limit 65535 bytes

-3

Hello.

I need to run the code below with values that exceed those allowed by the String of main, what do I do?

This is a list of numbers that exceeds 65535 characters.

Actually the program will be used for several sets, so the "a" is in braces

Due to the number of characters I put the data in Drive below:

    

asked by anonymous 16.04.2018 / 01:58

1 answer

0

As you've already noted, 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 should clearly not be declared within the program. Data must be saved to files in the hard drive, when a program needs them it will have to read the files that contain 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 there.

How to read a text file in Java?

    
12.05.2018 / 20:44