+ 1

Whats wrong with my code?

import java.util.Scanner; public class Program{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); String str = sc.nextLine(); String [] words = str.split(" "); String[] newWords = new String[words.length]; int i=0; for(String word : words){ char ch = word.charAt(0); newWords[i] = word.replace(ch, '\u0000') + ch + "ay"; i++; } String newSentence = String.join(" ", newWords); System.out.println(newSentence); sc.close(); } }

22nd Dec 2021, 6:30 AM
I.K.I.A.T.L
4 Réponses
+ 5
I.K.I.A.T.L , see my comments and modifications in the file: https://code.sololearn.com/cOoozgGm65N3/?ref=app
22nd Dec 2021, 3:53 PM
Lothar
Lothar - avatar
+ 6
I.K.I.A.T.L , i did not step very deep in your code, you can use both codes in an online debugger to see the difference.
22nd Dec 2021, 4:43 PM
Lothar
Lothar - avatar
+ 1
Lothar But what's wrong with my code ?!
22nd Dec 2021, 3:57 PM
I.K.I.A.T.L
0
In the line for (String : words) its bad, the correct one would be for(String words; words)
22nd Dec 2021, 12:09 PM
Álvaro Porras Jurado