my program has to print words backward with upper cases and at the end of every line print a dot. Can you please help me with deleting the last whitespace before the dot?
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int pocet = sc.nextInt();
sc.nextLine();
for (int i = 0; i < pocet; i++) {
String veta = sc.nextLine();
String veta2=veta.replaceAll("\\s+"," ");
String[] words = veta2.split(" ");
String result = "";
for (int j = 0; j<words.length;j++){
for (int k = words[j].length(); k > 0; k--) {
result = result + words[j].substring(k - 1, k);
}
words[j] = result;
result = "";
//return result.replaceAll("\\s+$", "");
}
words[words.length-1]= words[words.length-1];
System.out.println();
for (int j =0; j<words.length; j++){
char whitespace = ' ';
System.out.print(words[j].toUpperCase()+whitespace);
}
}
System.out.print(".");
System.out.println();
}
}
Thanks
words[words.length-1]= words[words.length-1];, you are doinga = a