reverse a string like i/p " java is the best" o/p "avaj is the best"
Sigiloso
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); String words[] = str.split(" "); // Reverse first word String first = words[0]; String rev = ""; for (int i = first.length() - 1; i >= 0; i--) { rev += first.charAt(i); } // Replace first word words[0] = rev; // Join back for (String w : words) { System.out.print(w + " "); } } }