15th May 2020, 5:55 AM
Harithra Shanmugam
5 ответов
+ 6
Indexes of string 'a' are in the range from 0 to a.length() - 1, but in the last iteration of for-loop you read char with index a.length() which is out of bounds. Line #10 should be for(int i=1;i<b;i++)
15th May 2020, 6:36 AM
andriy kan
andriy kan - avatar
+ 4
At first, you should convert each word of the string. Use split(" ") method to split the input string into words. To convert each word to piglatin you don't need to iterate that word. You just need to get substring starting from 2nd character, append the first character and append "ay". Or in code: Scanner sc=new Scanner(System.in); String a=sc.nextLine(); String result = ""; for(String w: a.split(" ")){ if(!result.isEmpty()) result += " "; result += w.substring(1) + w.charAt(0) + "ay"; } System.out.print(result);
15th May 2020, 7:47 AM
andriy kan
andriy kan - avatar
15th May 2020, 5:56 AM
Harithra Shanmugam
+ 2
andriy kan Didn't get my expected output. What's wrong in my 12th line?
15th May 2020, 7:11 AM
Harithra Shanmugam
15th May 2020, 7:12 AM
Harithra Shanmugam