- #1
Darkstar3000
- 29
- 0
I wrote this program and it keeps requesting input from me, could anyone take a look at it and tell me what's wrong ?
Thanks in advance :)
Code:
import java.io.IOException;
import java.util.Scanner;
import java.lang.String;
public class StringCW
{
private Scanner in = new Scanner( System.in );
String sentence, s, collect;
String lowercase = "";
char sub;
int i = 0;
public String readWords()
{
System.out.println( "Enter your sentence/word : " );
sentence = in.next();
for (; ; )
{
if(i < sentence.length())
{
lowercase = sentence.toLowerCase();
sub = lowercase.charAt( i );
if (sub == 's')
{
s = sentence.substring( i, (i + 4) ).toLowerCase();
if (s == "stop")
{
return ("\"" + lowercase + "\" ");
}
else
{
i++;
continue;
}
}
}
}
}
String splitString()
{
String a[] = new String[100];
System.out.println( "Enter your sentence : " );
sentence = in.next();
for (i = 0; i < sentence.length(); i++)
{
sub = sentence.charAt( i );
collect += sub;
collect.toLowerCase();
if (sub == 's')
{
s = sentence.substring( i, (i + 4) ).toLowerCase();
if (s == "stop")
{
return ("\"" + lowercase + "\" ");
}
else
continue;
}
if (sub == ' ')
{
a[i] = collect;
sub = ' ';
collect = "";
}
}
for (i = 0; i < sentence.length(); i++)
{
System.out.println( "\"" + a[i] + "\"" );
}
return ("Finished");
}
public static void main( String[] args ) throws IOException
{
StringCW obj = new StringCW();
obj.readWords();
obj.splitString();
}
/////////////////////////////////////////////////////////////////////////
} // End of class
Thanks in advance :)