Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HEAP MEMORY JAVA ERROR TRIED FIXING IN RUN CONFIGURATIONS WITH ARGUMENTS ALREADY

ID: 3835413 • Letter: H

Question

HEAP MEMORY JAVA ERROR TRIED FIXING IN RUN CONFIGURATIONS WITH ARGUMENTS ALREADY THANK YOU!!! HERE IS MY PROGRAM: import java.util.Scanner; import javafx.util.Pair; /** * * @author Sam Zonay this class contains the main line logic and executes the * program as instructed by assignment sheet * */ public class worker { public static void main(String[] args) { for (int z = 10000; z < 10000001; z *= 10) { AdjacencyMatrix adjacencyMatrix = new AdjacencyMatrix(z); int i = 1; while (i < z) { int u = i - 1; int v = i; adjacencyMatrix.makeEdge(u, v, 1); ++i; } long begin = System.nanoTime(); adjacencyMatrix.timer(z); long end = System.nanoTime(); long elapsed_timez = end - begin; System.out.println("The elapsed time for Adjacency Matrix with " + z + " vertices is: " + elapsed_timez); } } } IT IMPLEMENTS THIS: import java.util.Scanner; public class AdjacencyMatrix { private final int vertices; private int[][] adjacency_matrix; public AdjacencyMatrix(int z) { vertices = z; adjacency_matrix = new int[vertices + 1][vertices + 1]; } public void makeEdge(int to, int from, int edge) { try { adjacency_matrix[to][from] = edge; } catch (ArrayIndexOutOfBoundsException index) { System.out.println("The vertices does not exists"); } } public int getEdge(int to, int from) { try { return adjacency_matrix[to][from]; } catch (ArrayIndexOutOfBoundsException index) { System.out.println("The vertices does not exists"); } return -1; } public void timer(int z) { for (int i = 1; i <= z; i++) { for (int j = 1; j <= z; j++) { } } } }

Explanation / Answer

You may want to try starting it with more memory, using the -Xmx flag, e.g.

Or If you are ruunning in eclipse

On Eclipse menu, clicks Run -> Run Configurations.., select the Java application you want to run, clicks on theArguments tab, update the VM arguments with the following options

ex: -Xmx2048M