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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:04:55+00:00 2026-05-27T16:04:55+00:00

I know I’m doing something stupid, but I cannot figure how to fix it.

  • 0

I know I’m doing something stupid, but I cannot figure how to fix it.

The issue is inside the private method removeVowels particulry when using the vowels method.

The compiler gives

non-static variable vowels cannot be referenced from a static context

Here is my code:

   public class RecursionHW2 {

            String vowels;

            // Part (A) First way
            public static int upperCase(String myString){

                return upperCaseChecker(myString , 0 );
            }

            public static int upperCaseChecker(String myString, int index){

                int inc;

                //My Base Code
                if(myString.length() <= index) return 0;
                if(Character.isUpperCase(myString.charAt(index)) == true) inc= 1;
                    else inc= 0;

                return inc+upperCaseChecker(myString,index+1);
            }



            // First way of Solving part (B)
            public static int count(String str, char a)
            {
                if (str.length() == 0)
                    return 0;
                else if (str.charAt(0) == a)
                    return 1 + count(str.substring(1, str.length()), a);
                else
                    return count(str.substring(1, str.length()), a);
            }


            //Second way of solving part (B)
            public static int anotherCount(String myString, char myWord)
            {
                return anotherCount(myString, myWord, 0);
            }

            public static int anotherCount(String myString, char myWord, int index)
            {
                int inc;

                if (index >= myString.length())
                {
                    return 0;
                }

                if (myString.charAt(index) == myWord)  inc =1;
                    else
                        inc = 0;

                return inc + anotherCount(myString, myWord, index+1);
            }



            // part (C) solving
            public Boolean isSorted(int[] a, int n)
            {
            if(n == 0 || n == 1) return true;
            else
            return isSorted(a, n, 1);
            }

            private Boolean isSorted(int[] a, int n, int cur)
            {
                if(cur == n) return true;

                if(a[cur - 1] <= a[cur])
                    return isSorted(a, n, cur+1);
                else
                    return false;
            }



            //part (D) Solving
            public static String removeVowels(String myString)
            {
                return removeVowels(myString, "");
            }

            private static String removeVowels(String myString, String t)
            {
                if(myString.length() == 0) return t;

                if(vowels.contains(myString.charAt(0) + ""))
                    return removeVowels(myString.substring(1), t);
                else
                    return removeVowels(myString.substring(1), t + myString.charAt(0));
            }


        public static void main(String[] args){


            //I've wrote 2 ways to solve the Second Recursive Q2
            System.out.println("Method 1: Number of Occurence " + count("Hello  This is Mohammad Fadin",'o'));
        //  System.out.println("Method 2: Number of Occurence "+ anotherCount("Hello This is Mohammad Fadin",'o'));

            String s1 = "Hello WorlDD";
            System.out.println("Number of Upper Cases " + upperCase(s1));

            String s2 = "Hello";
            System.out.println("After Vowels Removed " + removeVowels(s2));
        }


    }
  • 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-27T16:04:56+00:00Added an answer on May 27, 2026 at 4:04 pm

    You’ve “infected” your code with static from your main method. In your main method you should do something like this, so you don’t have to make everything static:

    public class RecursionHW2
    {
      public static void main(String[] args)
      {
        RecursionHW2 rhw2 = new RecursionHW2();
    
        int count = rhw2.count("Hello world");
    
        // and so on
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Know this might be rather basic, but I been trying to figure out how
I know this is a stupid question, but I've looked for 45 mins now
I know that design patterns is generally something that's connected to OO programming, but
I know we already have many posts about this topic, but I just cannot
I know that there's something fishy about the malloc part, but I'm having trouble
I know that I can do something like $int = (int)99; //(int) has a
I know this might be a no-brainer, but please read on. I also know
I know, I would have thought the answer was obviously no as well, but
I know very little about Agile but I wonder if there is any difference
I know there are similar questions already on SO but none of them seem

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.