Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

How will these issues affect the grade levels you will teach?

Answered: 1 week ago