Skip to content
Snippets Groups Projects
Commit 1fe46905 authored by bjv33's avatar bjv33
Browse files

Java Sentences

parent edd909ff
No related branches found
No related tags found
No related merge requests found
// Program: JavaSentences.java
// Purpose: This program reads a one-line sentence as input from the user and then displays various responses.
// Author: Brian Vojtko
// Date: 10/16/2018
import java.util.Scanner;
public class JavaSentences
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//User Prompt
System.out.println("Enter Sentence: ");
//Identifiers
String sentence = sc.nextLine();
int sLen = sentence.length();
String sentenceEnd = sentence.substring(sLen-1, sLen);
//Output
if (sentenceEnd.equals("?") & (sLen % 2 == 0))
System.out.println("Yes");
else if (sentenceEnd.equals("?") & (sLen % 2 != 0))
System.out.println("No");
else if (sentenceEnd.equals("!"))
System.out.println("Wow");
else
System.out.println("You always say " + sentence + ".");
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment