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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:20:19+00:00 2026-06-14T06:20:19+00:00

I have to take a string and convert the string to piglatin. There are

  • 0

I have to take a string and convert the string to piglatin. There are three rules to piglatin, one of them being:

if the english word starts with a vowel return the english word + “yay” for the piglatin version.

So i tried doing this honestly expecting to get an error because the startsWith() method takes a string for parameters and not an array.

 public String pigLatinize(String p){
    if(pigLatRules(p) == 0){
        return p + "yay";
    }
}

public int pigLatRules(String r){
    String vowel[] = {"a","e","i","o","u","A","E","I","O","U"};
    if(r.startsWith(vowel)){
        return 0;
    }        
}

but if i can’t use an array i’d have to do something like this

if(r.startsWith("a")||r.startsWith("A")....);
     return 0;

and test for every single vowel not including y which would take up a very large amount of space, and just personally I would think it would look rather messy.

As i write this i’m thinking of somehow testing it through iteration.

 String vowel[] = new String[10];
 for(i = 0; i<vowel[]; i++){
     if(r.startsWith(vowel[i]){
         return 0;
     }

I don’t know if that attempt at iteration even makes sense though.

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

    Your code:

    String vowel[] = new String[10];
    for(i = 0; i<vowel[]; i++){
        if(r.startsWith(vowel[i]){
            return 0;
         }
    }
    

    Is actually really close to a solution that should work (assuming you actually put some values in the array).

    What values do you need to put in it, well as you mentioned you can populate the array with all the possible values for vowels. Those of course being

    String[] vowel={"a","A","e","E","i","I","o","O","u","U"};
    

    now you have this you would want to loop (as you worked out) over the array and do your check:

    public int pigLatRules(String r){
        final String[] vowels={"a","A","e","E","i","I","o","O","u","U"};
        for(int i = 0; i< vowels.length; i++){
            if(r.startsWith(vowels[i])){
                 return 0;
             }
        }
        return 1;
    }
    

    There are some improvements you can make to this though. Some are best practice some are just choice, some are performance.

    As for a best practice, You are currently returning an int from this function. You would be best to change the result of this function to be a boolean value (I recommend looking them up if you have not encountered them).

    As for a choice you say you do not like having to have an array with the upercase and lowercase vowels in. Well here is a little bit of information. Strings have lots of methods on them http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html one of them is toLowerCase() which as you can guess lowercases a whole string. if you do this to the work you pass in to your function, you cut the amount of checks you need to do in half.

    There is lots more you cam get into but this is just a little bit.

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

Sidebar

Related Questions

I have got a function which is use to take a string and convert
I have a file I converted into one long string. I want to take
I have written two methods that take and return a string. One converts from
As input, I have a date string that can take three general formats: a)
How to convert string that have \r\n to lines? For example, take this string:
I have this very simple br2nl function that I use to take a string
hey I have a string as such: 357902||190||RUE RACHELLE||ST|||LES CÈDRES|J7T1J9|QC I wish to take
Take the following example, I have a class public class SomeItem { public string
I have a Dictionary<int, string> which I want to take the Key collection into
I have an application, currently written in C#, which can take a Base64-encoded string

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.