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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:31:01+00:00 2026-06-18T07:31:01+00:00

Okay guys,I need to solve this problem using minimum if else condition.Let me explain

  • 0

Okay guys,I need to solve this problem using minimum if else condition.Let me explain my problem.
Suppose there are three String city,state and country.I need to print it in following format

city,state,country

In case if city=”” then it needs to be

state,country

In case if state=”” the it needs to be

 city,country

if country=”” then

city,state

if all string are”” then nothing should be printed or just a “”.
and every other possible conditions.Those three strings may have value or may contain “” not null.So using least if else condition i need to solve this problem.
Note:Not a homework.

  • 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-18T07:31:03+00:00Added an answer on June 18, 2026 at 7:31 am
    StringBuilder sb = new StringBuilder ();
    for (String s: new String [] {city, state, country})
    {
        if (!s.isEmpty ())
        {
            if (sb.length () > 0) sb.append (",");
            sb.append (s);
        }
    }
    System.out.println (sb);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay guys, basically the problem I'm having is this. I've been assigned to write
Okay guys hopefully I can explain this effectively, so here goes. I have a
Okay guys, I am working hashmap, using one of my classes as Key. My
Okay, before you guys go nuts -- this is just a small site, temporary
Okay guys, maybe you can help me out with this one. I'm about ready
Okay guys I have a question about positioning tables within DIV's using CSS. I
Okay guys, I'm sure this has a very simple solution but my searches are
okay guys Same question as everyone else. I got it to work if i
Okay the title cannot explain the situation correct enough. Now this is it, I
Okay guys, I'm ready to bloody give up on this thing, I think I'm

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.