There's a program I'm working on which deals with sentences, words and punctuations. It removes excess spaces from the sentences.
This is my code:
import java.util.*;
class Prog10
{
static void main()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a sentence:");
String out="";
for(String i:sc.nextLine().split("[\\s]"))
out+=i+(<last-iteration-condition>?"":" "); //Using regex to clean excess spaces
System.out.print(out);
}
}
I'm wanting to detect the last iteration without any new additions to code except for the boolean condition. No as an answer would also suffice.