0
[SOLVED]Has anyone solved Pig Latin From CodeCoach in Java?
Need to find out some edge cases.
9 Respuestas
+ 3
NITISH 
AY is a variable name? 
I changed each AY into "ay" and found this:
input: "o"
output: "ayo"
But it should be "oay"
hello -> put the first letter to the end -> elloh and add ay -> ellohay
o -> first letter to the end -> still o + ay -> oay
Hope this makes clear why one letter results in letter + ay
+ 3
NITISH using replace to remove the first letter ends up replacing all occurances. I think substring would work better.
+ 2
I solved this challenge. If you want you can show me your code.
Edge case? Maybe when your input string contains only one letter.
And I would check if you insert unwanted spaces or in general what happens when you get more than one word.
e.g. "hello world" -> "ellohay orldway"
+ 1
Where you are blocked?
+ 1
Well, it's working... but I think it's too messed up. Any suggestions?
public static String AY = "ay";
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
        String str = scan.nextLine();
        String temp = str;
        
        String strArr[] = str.split(" ");
        String res = " ";
        
        if(temp.length() > 1){
        for(String st : strArr){
            String sb = st.substring(0,1);
            
            String stt = st.substring(1, st.length());
            String rest = stt+sb+AY;
            
            res = res +" "+ rest;
            //System.out.print(rest.trim()+" ");
        }
        System.out.println(res.trim());
        }else if(temp.length()==1){
            System.out.println((str.trim())+AY);
        }else{
            System.out.println(AY);
        }
    }
+ 1
No Is not a variabile. You can Simply use toString() like this: text + "ay"
+ 1
Is more simplex Nitish. When you have split the text into Array... Cicle the Array and join every element with each other adding +"ay"
0
I share code as public let you see...
0
👍 👍 👍



