Write a Java program to capitalize the first letter of each word in a sentence.
For this, I have written a java program but it is throwing an error
"result of string.replace(),is ignored";
my code
package com.company;
import java.util.Scanner;
public class uppercase_1srchar_of_string {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("enter the string :");
String a = sc.nextLine();
for(int i = 0; i < a.length(); i++) {
if(a.charAt(i) == ' ') {
char c;
char d;
c = a.charAt((i + 1));
d = Character.toUpperCase(c);
a.replace(a.charAt((i + 1)),d);
}
}
System.out.println(a);
}
}
I don't know where I did make a mistake.