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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:07:29+00:00 2026-06-13T22:07:29+00:00

I am creating a program and part of the program receives an expression with

  • 0

I am creating a program and part of the program receives an expression with the following conditions:

  • Allowed chars: “1234567890+-*/() ” — notice the space at the end of them

  • Must be balanced

  • Starts and ends with “(” and “)”

  • The separation is a single white space between each operator, operand or/and parenthesis:

I have done the first two conditions, but I am stuck with the third one.

Examples:

( 1 + ( ( 22 – 322 ) * 4 / 5 ) ) <<< Valid

( 1+ ( ( 22 – 322 ) * 4 / 5 ) ) <<< Invalid

( 1 + (( 22 – 322 ) * 4 / 5 ) ) <<< Invalid

( 1 + ( ( 22 – 322 )* 4 / 5 ) ) <<< Invalid

Here is what I have done so far:

public static boolean isSSWS(String e) {

    boolean valid = false;
    int indexOfWS = 0;
    Character preChar = '\0';
    Character postChar = '\0';

    while(!valid && (indexOfWS < e.length())) {
        indexOfWS = e.indexOf(" ", indexOfWS + 1);
        preChar = e.charAt(indexOfWS - 1);
        postChar = e.charAt(indexOfWS + 1);

        if(preChar == ' ' || postChar == ' ') {
            return false;
        }
    }

    return true;
}

isSSWS, is *S*eparated with *S*ingle *W*ite *S*pace

indexOfWS, index of white space

  • 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-13T22:07:30+00:00Added an answer on June 13, 2026 at 10:07 pm

    Edited, I didn’t notice that numbers shouldn’t have spaces. Bit messy, but works for all inputs I’ve tried.

    public static boolean isSSWS(String s) {
        boolean isWhiteSpace = false;
        boolean isPreviousCharDigit = false;
    
        for (char c : s.toCharArray()) {
            if (!isPreviousCharDigit || !Character.isDigit(c)) {
                if (c == ' ' && !isWhiteSpace) {
                    return false;
                }
                if (c != ' ' && isWhiteSpace) {
                    return false;
                }
                isWhiteSpace = !isWhiteSpace;
            }
            isPreviousCharDigit = Character.isDigit(c);
        }
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a windows service program which invokes a java program. Here is part
I am creating random number generator in Java as part of program I am
Part of a Java program I'm creating needs to talk to a service on
What is the guideline on creating a program or part of a program based
Part of the program that I am creating requires that I ask the user
I creating a program which send newsletter with a background image. It works fine
Bassicly im creating a program that reads information from an xml file into a
I am creating a program used to connect to a embedded bluetooth device with
I'm creating a program in VB.NET to output multiple images. Some images will have
I'm creating a program to open .txt files in a given directory, 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.