Alright i am writing a program to read a sentence you write and judging by you punctuation it will tell you whether its a statement, question, exclamation or other. My problem is that it isnt running my If statement. am i just bind and missing something.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication17;


import java.util.*;


/**
 *
 * @author Austin Skarphol
 */
public class Main {




    /**
     * @param args the command line arguments
     */

    public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
   char Find[]={'.','!','?'};
   String find = new String(Find);
    System.out.println("Please type a sentence with correct punctuation. >");
    String Word = scan.next();


if (Word.indexOf(find) != -1)
    System.out.println("this is a statment");
else if (Word.indexOf(find)!= -1)
        System.out.println("This is an exclamation");
else if (Word.indexOf(find)!= -1)
            System.out.println("This is a question");
        



 

    }
}

Nvm i have found it.

First i got rid of the array and added each Char to the indexOf and then add one like for the else output if its none of these.

I just figured out that your program is reading only word instead of whole line. Can you please try to print content of 'WORD' after

String Word = scan.next();

line.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.