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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:21:09+00:00 2026-06-13T06:21:09+00:00

This is an assignment question I received from school. The question says, write a

  • 0

This is an assignment question I received from school. The question says, write a method called capitalizer which will take the string “ownage” and then displays(doesn’t have to return) all the possible capitalization of it, such as “OwNaGE” or “OWnAGE”. It doesn’t have to work for every string, just the word “ownage” is enough, and it has to be done with recursion.

Here’s what I have so far.

import java.util.*;

class MethodAssign2{
   static void capitalizer(String a,int b){
      if(b==-1){
         System.out.println("worked?");
      }else{
         char[] achars = a.toCharArray();
         achars[b] -= 32;
         String caplet = new String(achars);
         System.out.println(caplet);
         System.out.println(a);
         capitalizer(caplet,b-1);
         capitalizer(a,b-1);
      }
   }
   public static void main(String[]args){
      String word = "ownage";
      capitalizer(word,word.length()-1);
   }
}

My mind is completely messed up right now. It seems like I have lots of repeated cases. Do you guys think I’m close the right solution? How do I make it so that nothing happens in the base case rather than printing out something? How do I avoid the repeats? Anyone please help me I would appreciate it very much.

  • 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-13T06:21:10+00:00Added an answer on June 13, 2026 at 6:21 am

    To avoid the repeats – you should print your string only in the stop clause, and not in every iteration.

    static void capitalizer(String a,int b){
        if(b==-1){
            System.out.println(a); //CHANGE: printing in the stop clause
        }else{
            char[] achars = a.toCharArray();
            achars[b] -= 32;
            String caplet = new String(achars);
            //CHANGE: not printing every iteration
            capitalizer(caplet,b-1);
            capitalizer(a,b-1);
        }
    }
    

    The idea if the algorithm is: In each stage you “guess” what is the current character – is it an upper or lower character, and invoke the algorithm recursively on the smaller problem (with the next character).

    You repeat this for both the current letter is and is not capitalized.


    The previous code failed because you printed the strings it generated after every letter change, which results in much more (almost double) then all 2^n1 possible ways to print the word.


    (1) Bonus: There are exactly 2^n possible strings you can print, because for every character you need to chose: Is it capitalized or not? You repeat this question for each character, and from rule of product – it gives you exactly 2^n possible strings.

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

Sidebar

Related Questions

This is an assignment question from school: Create a recursive method called toBinary that
I've this question from an assignment to create a Store which rent out books,
A recent homework assignment I have received asks us to take expressions which could
This is a question corresponds to my uni assignment so I am very sorry
For this assignment I had to create my own string class. I initially wrote
I swear this assignment will be the end of me, I've been researching this
As part of this assignment for my class, in which I have a listbox
In conjunction from my another question , and after changing this small part of
I have got this assignment question on HMM and I have solved it. I
This is an assignment question that I am having trouble wording an answer to.

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.