jeudi 13 juin 2019

Three syntax errors, not sure what i'm doing wrong. Beginner code, if-else statements

I'm trying to code a program that will give specific responses when a sentence is input.

[[ If the sentence ends with a question mark (?) and the input contains an even number of characters, display the word Yes.

If the sentence ends with a question mark and the input contains an odd number of characters, display the word No.

If the sentence ends with an exclamation point (!), display the word "Wow".

In all other cases, display the words "You always say" followed by the input string enclosed in quotes. ]]

tried moving my brackets around, tried doing what the errors suggested, nothing worked.

`

import java.util.Scanner;
public class Chapter3ProgrammingProject4_JM
{
public static void main(String[] args)
 {
  Scanner keyboard = new Scanner(System.in);


 System.out.println("Please enter a sentence.");
{
 String word;
 word = keyboard.nextLine();

if ((word.endsWith("?")))
if ((word.length() %2==0))
{
   System.out.println("Yes");

} 

else if ((word.length() %2!=0));

  System.out.println("No");


 if((word.endsWith("!")))

  System.out.println("Wow");

 else 
 System.out.println("You always say " + \" + word + \");

   }
  }
 }

3 errors found: [line: 31] Error: Syntax error, insert ")" to complete MethodInvocation [line: 31] Error: Syntax error, insert ";" to complete Statement [line: 31] Error: Syntax error, insert "}" to complete Block

Aucun commentaire:

Enregistrer un commentaire