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

  • Home
  • SEARCH
  • 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 7707963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:29:24+00:00 2026-06-01T00:29:24+00:00

I create an array that then prints in sets of five. I want to

  • 0

I create an array that then prints in sets of five. I want to then be able to search the array by 5 to see if there are any duplicates. I’ve tried but I can only think of a way to search by each value not five. If anyone can point me in the right direction, that would be great. Thanks.

 public class findPat {
        static int arr [] = new int [10];
        static int st = 1;
        static int end = 56;
        static double t1;
        static double t2;

        public static void main(String[] args){

            t1=System.currentTimeMillis(); 
            for(int n=0; n<100; n++){   
                for (int i=0; i<arr.length; i++)
                    arr[i]= (int) (Math.random()* (end-st +1)) +st;

                for (int i=0; i<5; i++){ 

                    if (i%5==0) 
                        System.out.println(); 
                        System.out.print("\t" + arr[i]);} 
                    }
            t2=System.currentTimeMillis();
            System.out.println();
            System.out.println();
            System.out.println("\t" + "Total run time is " + ((t2-t1)) + "ms");

            }
        }

the console looks like this:

    18  22  42  14  38
    2   2   14  9   8
    6   29  38  37  33
    6   41  41  27  7
    20  41  38  11  50
    16  17  41  21  19
    40  33  9   10  7
    12  54  10  30  36

however each row is in the same array but is just printing 5 at a time.
the console will have more than just those few lines. I want to be able to search the array and check each row against the rest to see how many times it appears, if it does.

  • 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-01T00:29:25+00:00Added an answer on June 1, 2026 at 12:29 am

    You could implement this using a Hashtable. Using your code as a base, I’ve written an example implementation but without knowing what it is you are trying to do, I can’t judge if this is what you are looking for.

    import java.util.Hashtable;
    
    public class findPat {
        static final int COUNT = 100;
    
        static Hashtable<String, Integer> compareSet = new Hashtable<String, Integer>();
        static String groupInteger = "";
        static int arr [] = new int [5];
        static int st = 1;
        static int end = 56;
        static double t1;
        static double t2;
    
        public static void main(String[] args) {
            t1=System.currentTimeMillis(); 
            for(int n = 0; n < COUNT; n++){
                for (int i = 0; i < arr.length; i++) {
                    arr[i] = (int) (Math.random()* (end - st + 1)) + st;
    
                }
                for (int i = 1; i <= 5; i++) {
                    groupInteger += arr[i-1];
                    System.out.print("\t" + arr[i-1]);
                    if (i % 5 == 0) {
                        System.out.println();
                        if (compareSet.containsKey(groupInteger)) {
                            System.out.println("duplicate found");
                            int currentCount = compareSet.get(groupInteger);
                            compareSet.put(groupInteger, currentCount + 1);
                        } else {
                            compareSet.put(groupInteger, 1);                        
                        }
                        groupInteger = "";
                    }
    
                } 
            }
            t2=System.currentTimeMillis();
            System.out.println();
            System.out.println();
            System.out.println("\t" + "Total run time is " + ((t2 - t1)) + "ms");
        }
    }
    

    This code keeps track of the unique sets of random numbers by adding them (creating a key value that is the same for every set that has the same values in the same order, the concatenated string takes care of this).

    Your code ran in 13 seconds on my system, mine takes 17 seconds. Now if runtime is of crucial importance, you might want to look into hashing techniques. But I’m not sure if you will be able to shave off a lot as you will have to add some extra code which will take extra time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine that I want to create an array from another array like this: $array
I was trying to create an extension that could slice any array-like class (since
I have a page that creates an associative array, then passes it as a
I am trying to create an array or list that could handle in theory,
I'm trying to create an array of strings that can be randomized and limited
I have a 3x3 array that I'm trying to create a pointer to and
I am trying to create a UIImage from a byte array that is actually
Given that EVAL is Evil how do I create an Array name dynamically: I
I'm trying to create an array of structs and also a pointer to that
Im trying to create a method that take 2 int array as the input

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.