I want to check if the current current is char ',', '-', '.' or '' Is there a shorter expression for:
if((current != ' ') || (current != '.') || ...)
any ideas?
EDIT:
I am just allowed to use the nextChar and getChar methods. I need to scroll characters.
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class WoerterZaehlen {
public static void main(String[] args) {
int wordCount = 0;
char previous = ' ';
while(hasNextChar()){
char current = getChar();
if(current != )
previous = current;
}
System.out.println("Anzahl der Wörter: " + wordCount);
}
private static InputStreamReader reader;
private static int next = -1;
public static boolean hasNextChar() {
if(next != -1)
return true;
try {
if(reader == null)
reader = new InputStreamReader(new FileInputStream("textdatei.txt"));
next = reader.read();
} catch (IOException e) {
System.out.println("Datei wurde nicht gefunden.");
}
return next != -1;
}
public static char getChar() {
char c = (char) next;
next = -1;
return c;
}
}
source
share