Question
my method dosent print the last procces please help me fix it public static void reportMemory() { int start = -1; int end = -1;
my method dosent print the last procces please help me fix it
public static void reportMemory() { int start = -1; int end = -1; int currentProcess = -1;
for (int i = 0; i < MAX; i++) { int address = addresses[i]; if (address != 0) { if (currentProcess == -1) { // First used address found start = i; currentProcess = address; } else if (address != currentProcess) { // New process found end = i - 1; System.out.printf("Addresses [%d, %d] Process P%d ", start, end, currentProcess - 1); start = i; currentProcess = address; } } else { if (currentProcess != -1) { // End of used address range found end = i - 1; System.out.printf("Addresses [%d, %d] Process P%d ", start, end, currentProcess - 1); currentProcess = -1; } } }
// Check if there's a range of unused addresses at the end if (currentProcess == -1) { System.out.printf("Addresses [%d, %d] Unused ", end + 1, MAX - 1); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started