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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:22:07+00:00 2026-06-15T10:22:07+00:00

I am just wondering if anyone could show me some code as to how

  • 0

I am just wondering if anyone could show me some code as to how I would put this string in a 2D boolean array and print it out

Example: “0-1 0-2 1-2 1-3 2-3” , however the string could be more complicated like this “0-1 1-2 2-3 3-0 0-4 0-11 1-5 1-6 2-7 2-8 3-9 3-10 4-5 6-7 8-9 10-11 4-7 4-8 5-9 5-10 6-9 6-10 7-11 8-11”

An example would be 0-1 is true, 0-2 is true, 1-2 is true, 1-3 is true, 2-3 is true, all other postions should be false

  • 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-15T10:22:08+00:00Added an answer on June 15, 2026 at 10:22 am

    I don’t know what you mean by putting them in a 2D boolean array. If you have problem with parsing the text, then here are some snippet of code you can use.

    For the first solution, I assume that the numbers always come in pairs and are separated by a single -, and space is used to delimit between the pairs of numbers.

    Use this if you are reading from standard input:

    Scanner scanner = new Scanner(System.in);
    

    Use this if you have a String contains all the numbers and you want to process it (let the name of the variable be inputString):

    Scanner scanner = new Scanner(inputString);
    

    Then you can read the numbers from the input:

    while (scanner.hasNext()) {
        String pair = scanner.next();
        // Split by the hyphen
        String tokens[] = pair.split("-");
    
        // Normally, one should check the array before accessing it
        // I currently assume the input is valid
        int first = Integer.parseInt(tokens[0]);
        int second = Integer.parseInt(tokens[1]);
    
        // Do whatever you want with the 2 numbers extracted
    }
    

    Alternatively, you can also use useDelimiter to add - as delimiter and use nextInt to read number without having to deal with - separately:

    scanner.useDelimiter("[\\p{javaWhitespace}-]+");
    

    The code will simply becomes:

    scanner.useDelimiter("[\\p{javaWhitespace}-]+");
    
    while (scanner.hasNext()) {
        int first = scanner.nextInt();
        int second = scanner.nextInt();
    
        // Do whatever you want with the 2 numbers extracted
    }
    

    The code is cleaner, but whether - appear between first and second, or how many - appear, or is it the only character between the pair of numbers not is not known now. It is OK if we assume the input format is correct. However, if that assumption is not given, we can’t do any input validation.

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

Sidebar

Related Questions

was wondering if anyone could help me improve my code. Its just some basic
Just wondering if anyone else has spotted this: On some user's machines running our
Just wondering if anyone could help me with this. I'm new to actionscript, and
I was just wondering if anyone could help out with how to do the
just wondering if anyone could show me how to do a couple simple commands
I’m just wondering if anyone’s come across or could recommend an IDE that’s capable
Just wondering if anyone can optimize this usortMonths() function to be better? Basically I
Just wondering if anyone has some good resources for learning how to create new
I am just wondering if anyone know of some good tutorials on the Internet
I was just wondering if anyone could explain to me how a price comparison

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.