[SOLVED]Has anyone solved Pig Latin From CodeCoach in Java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[SOLVED]Has anyone solved Pig Latin From CodeCoach in Java?

Need to find out some edge cases.

31st Jan 2022, 6:00 PM
NITISH
NITISH - avatar
9 Answers
+ 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
31st Jan 2022, 7:04 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
NITISH using replace to remove the first letter ends up replacing all occurances. I think substring would work better.
31st Jan 2022, 11:02 PM
Brian
Brian - avatar
+ 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"
31st Jan 2022, 6:35 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Where you are blocked?
31st Jan 2022, 6:41 PM
Marco Ginato
Marco Ginato - avatar
+ 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); } }
31st Jan 2022, 6:54 PM
NITISH
NITISH - avatar
+ 1
No Is not a variabile. You can Simply use toString() like this: text + "ay"
31st Jan 2022, 8:06 PM
Marco Ginato
Marco Ginato - avatar
+ 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"
31st Jan 2022, 8:10 PM
Marco Ginato
Marco Ginato - avatar
0
I share code as public let you see...
1st Feb 2022, 7:39 AM
Marco Ginato
Marco Ginato - avatar
0
👍 👍 👍
1st Feb 2022, 2:58 PM
Jahongir Normurotov 16 Years