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 7016223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:45:24+00:00 2026-05-27T22:45:24+00:00

So my code is done, but now I need it to print out wether

  • 0

So my code is done, but now I need it to print out wether the chosen numbers are equal or not!

I’ve made a loop for FALSE / NUMBERS ARE EQUAL, but it doesn’t work properly.
Hope you can help.
My code looks like this:

package patternrecognition;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.TreeMap;

public class PatternRecognition {

    public static void main(String[] args) throws Exception {



        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));


        int AntalNumre = -1;

        boolean Gyldignummer = false;
        while (Gyldignummer == false) {
            System.out.print("\n\nIndtast antal numre: ");

            String numre = reader.readLine().trim();

            Gyldignummer = validInteger(numre);

            if (Gyldignummer == false) {
                System.out.println("Indtast et gyldigt nummer");
            } else {

                AntalNumre = Integer.parseInt(numre);
            }

        }


        HashMap vaerdier = new HashMap();

        for (int i = 0; i < AntalNumre; i++) { //Studerendes nummer(i+1)

            boolean GyldigNummer2 = false;

            while (GyldigNummer2 == false) {
                System.out.print("\n\nIndtast en vaerdi for nummer " + (i + 1) + ": ");

                String vaerdi = reader.readLine().trim();
                int vaerdien = -1;

                GyldigNummer2 = validInteger(vaerdi);
                if (GyldigNummer2 == false) {
                    System.out.println("Indtast et gyldigt nummer");
                } else {

                    vaerdien = Integer.parseInt(vaerdi);
                }
                vaerdier.put(vaerdi, new Integer(vaerdien));
            }
        }



        TreeMap SorteretNummer = new TreeMap(vaerdier);

        Iterator nr = SorteretNummer.keySet().iterator();

        System.out.println("\n\n\n\n\n");
        System.out.println("Numre valgt:");
        System.out.println("------------");


        while (nr.hasNext()) {

            String navn = (String) nr.next();


            int numre = ((Integer) SorteretNummer.get(navn)).intValue();

            System.out.println("" + numre);

            if (numre != numre) {
                System.out.println("FALSE");
            }
            else {
                System.out.println("ALLE THE NUMBERS ARE EQUAL");
            }

        }
    }

    public static boolean validInteger(String nummer) {
        boolean validInteger = false;


        try {
            Integer.parseInt(nummer);
            validInteger = true;
        } catch (NumberFormatException nfe) {
            validInteger = false;
        }
        return validInteger;

    }
}
  • 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-05-27T22:45:24+00:00Added an answer on May 27, 2026 at 10:45 pm

    Well, numre != numre is bound to be false unless of course numre happens to be changed in another thread (or be NaN, but that’s a different story).

    Perhaps, you may want to compare pairs of numbers? Or, perhaps, you want to have a data structure holding the numbers you’ve already seen (e.g. HashSet or BitSet)?

    An example: as user enters numbers, save those to a HashSet<Integer>. As soon as he’s done, add

    Set<Integer> set = new hashSet<Integer>();
    
    // ...as we're getting numbers from user
    
       set.add(numre);
    
    // ...
    
    if (set.size() == 1) 
        System.out.println("OMG they're all the same! " + set);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen both done in some code I'm maintaining, but don't know the difference.
I need to convert some code done by someone else, to work in my
I have a particular need which I cannot seem to figure out. I've done
Once a 10-fold cross-validation is done with a classifier, how can I print out
It's weird because I have done it before but it just is not working.
Brad Wilson states that The default templates in ASP.NET MVC are done in code.
I have done the following code in JavaScript to put focus on the particular
Has anyone done this / have some example code?
I've done most of my code in as3, working from either document class or
Where in code should conversions be done? client, server, business, or db? We currently

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.