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?