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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:48:30+00:00 2026-05-27T18:48:30+00:00

I have for two days tried to get my program to work, this is

  • 0

I have for two days tried to get my program to work, this is indeed a homework-assignment and a think my algorithm should be right, using a stack to check if the tags are balanced. I would be grateful if someone knows what is wrong with the code. This is what it looks like now:

public class HtmlParser {

    private Stack<String> tagstack; // stack to collect only "<" characters.

    public HtmlParser() {
        tagstack = new Stack<String>(); 
    }

    private void processClosedTag(Scanner in) {
        tagstack.pop();
        in.next();
    }

    private void processOpenTag(Scanner in) {  
        tagstack.push(in.next()); // "<"
    }

    public boolean isCorrectlyNested(Scanner in) {
        boolean isBalanced = false;
        while(in.hasNext()) {
            if(in.hasNext("<")) 
                processOpenTag(in); //and recurse until "/>"
            else if(in.hasNext(">")) 
                processClosedTag(in);
        }
        if(tagstack.isEmpty())
            isBalanced = true;
        return isBalanced;

    }//isCorrectlyNested

}//class

When I use the scanner object “in” and call for the methods in this class nothing happens in the console it only reads the what I write but then nothing happens it doesn’t even return my statements I have written like:

if(parser.isCorrectlyNested(input))
  System.out.println("Correctly Nested!"); 
else
  System.out.println("Need to nest properly");

This is of course in the main method where i use the HtmlParser instance “parser”.

  • 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-27T18:48:31+00:00Added an answer on May 27, 2026 at 6:48 pm

    You never actually move the scanner’s position if the next item is neither a less-than or greater-than symbol. Consider if the next character was an alpha-numeric string of some kind. Your while loop never returns because it never actually moves past the string if it isn’t what it is looking for, so your method never returns and your output never gets executed.

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

Sidebar

Related Questions

After wasting two days with this question (and trying to make it work), I've
In the last two days I tried to import this Library through Maven: https://github.com/JakeWharton/Android-ViewPagerIndicator
I been struggeling with this problem for two days now and have still not
I have been dealing with this for at least two days now. I don't
I have been studying unicode and its Python implementation now for two days, and
I've spent two days on this and I still can't find the cause of
Goal: Get values which are unique in $resultSecond So I have two objects. $result
Routing make me crazy thees days :( I have two areas: CityPage and Job
I've spent two days on this so far and combed through every source at
I've spent the last 2 days trying to figure this out, basically I have

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.