Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8913577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:29:51+00:00 2026-06-15T04:29:51+00:00

I’m supposed to be going through an array of these numbers, 7 0 1

  • 0

I’m supposed to be going through an array of these numbers, 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 then putting the first (non-repeating numbers) into a smaller array that holds only 5 of the numbers.

So after the first five are in, it would look like 7 0 1 2 3 (since 0 was already present within the array).

Then its supposed to search through and compare each element in the rest of the larger array with every element in the smaller one. T

The next element in the larger array is 0, the program needs to compare 0 to all the elements in the smaller array.

If the element exists in the smaller array, its just supposed to set a MRU variable equal to the index of the element that exists within the smaller array.

If the number doesn’t exist, say like after the next run, 4. Then the program will replace the element at the MRU variable with the number 4.

I have two questions,

  1. this program just spits back out to me the original numbers and idk, why?
  2. where do i go from here?

I’ve worked on this for many days and gone through countless variations. Its already passed the due date, but I want to learn how to do this.

   import java.util.*;
   import java.io.*;

   public class MRUPageReplacement
   {
    public static void main(String [] args)
   {
  //======== Variables ==============================================
     ArrayList<Integer>MRUList = new ArrayList<Integer>();
     int [] frames = {7,0,1,2,3};
     int i,j,MRU;
     String line;


  //======== File Reader ============================================
     try
     {      
        FileReader reader = new FileReader("MRU.txt");      
        BufferedReader r = new BufferedReader(reader); 
        while ((line=r.readLine())!=null)
        {
           MRUList.add(Integer.parseInt(line));
        }
     }
        catch(Exception e)
        {
           System.out.println("File Not Found");
        } 

     int[] array = new int [MRUList.size()];
     for (i =0; i < MRUList.size(); i++)
     {
        array[i] =  MRUList.get(i);
     } 

  //======== Fill Arrays ============================================== 


  //======== Compare ==============================================       
     for(i=0; i<array.length; i++) 
        {     // Iterate through the array
        for( j=0; j<frames.length; j++) 
            {   // Iterate through frames
           if(array[i] == frames[j]) 
                {
            // if the element is in frames
            MRU = j;
           }
           else {
           // if the element is not in frames
            frames[MRU] = array[i];   

           }
        }
     }


  /*======== Print ==============================================
     for(i=0; i<frames.length; i++)
     {
        System.out.println("frames : " + frames[i]);
     }  
  */

  }
}




// Sample output
frames : 7
frames : 0
frames : 1
frames : 2
frames : 3
frames : 0
frames : 0
frames : 1
frames : 2
frames : 3
frames : 0
frames : 1
frames : 1
frames : 2
frames : 3
frames : 0
frames : 1
frames : 2
frames : 2
frames : 3
frames : 0
frames : 1
frames : 2
frames : 2
frames : 3
frames : 3
frames : 1
frames : 2
frames : 2

On a side note, when I try and print out the array instead of just the numbers it gives this: [I@565b540e. Is that because it’s printing the index?

Eventually I would like to print out the frames array each time it runs through. Like:
Run 1: Frames = {70123}.

EDIT: Ok so after some amazing help from Noctua, im now running into the main problem i was having before. It only recognizes the first or second iteration i can’t tell since the second number is supposed to be a zero. Here is the part thats messing up:

for(i=0; i<array.length; i++) 
     {     // Iterate through Array 
        for( j=0; j<frames.length; j++) 
        {   // Iterate through Frames 
           if(array[i] == frames[j]) 
           {
            // Item from Array exists in Frames
              MRU = j;
              MRU_found = true;
           }
        }
        if(!MRU_found) 
            {
           frames[MRU] = array[i];
        }

I’ve worked at it from a couple angles, however nothing seems to be working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:29:52+00:00Added an answer on June 15, 2026 at 4:29 am
    for(i=0; i<array.length; i++) {        // Iterate through the array
        for( j=0; j<frames.length; j++) {  // Iterate through frames
           if(array[i] == frames[j]) { // if the element is in frames
               MRU = j;
           } else {
               // if the element is not in frames
               frames[MRU] = array[i];   
           }
        }
     }
    

    Here’s where’s your mistake. In stead of searching the whole frames array and then checking if you’ve met the frame, you’ve placed the else-clause inside your loop.

    What you probably meant, was something like:

    for(i = 0; i < array.length; i++) {
        for(j = 0; j < frames.length && !MRU_found; j++) {
            if(array[i] == frames[j]) {
                MRU = j;
                MRU_found = true;
            }
        }
        if(!MRU_found) {
            frames[MRU] = array[i];
        }
    }
    

    EDIT: On your side question, what you’re printing is the address of the array in the memory.

    To print the array each time, change the code to:

    for(i = 0; i < array.length; i++) {
        for(j = 0; j < frames.length && !MRU_found; j++) {
            if(array[i] == frames[j]) {
                MRU = j;
                MRU_found = true;
            }
        }
        if(!MRU_found) {
            frames[MRU] = array[i];
        }
        System.out.print("frams: {");
        for(j = 0; j < frames.length; j++) {
            System.out.print(" ");
            System.out.print(frames[j]);
        }
        System.out.println(" }");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.