Question: import java.util.Scanner; public class main { public static void main ( String [ ] args ) { Scanner scnr = new Scanner ( System .

import java.util.Scanner;
public class main {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
String userCaption;
userCaption = scnr.nextLine();
// Check for ! or ? which don't require any action
if (userCaption.endsWith("!")|| userCaption.endsWith("?")){
System.out.println(userCaption);
}
// Check for , and replace it with a period
else if (userCaption.endsWith(",")){
String correctedCaption = userCaption.substring(0, userCaption.length()-1)+".";
System.out.println(correctedCaption);
}
// Check for two ending periods
else if (userCaption.length()>=2 && userCaption.endsWith("..")){
// Check for three ending periods, no action required
if (userCaption.length()>=3 && userCaption.endsWith("...")){
System.out.println(userCaption);
} else {
// Remove the last period
String correctedCaption = userCaption.substring(0, userCaption.length()-1);
System.out.println(correctedCaption);
}
}
// No special cases, add a period
else {
String correctedCaption = userCaption +".";
System.out.println(correctedCaption);
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!