I am trying to write a program that takes a string as input.
This string must be an equation with only brackets, operations or digit.
The code I posted below is what I came up with, but when I run it, anything I enter is apparently an invalid string. Can someone please tell what I did wrong?
System.out.println("Enter a string");
String str = s.nextLine(); //s is a Scanner object
int n = str.length();
for(int i = 0; i < n; i++) {
if( !Character.isDigit(str.charAt(i)) || str.charAt(i) != '+'
|| str.charAt(i) != '-' || str.charAt(i) != '*'
|| str.charAt(i) != '/' || str.charAt(i) != '('
|| str.charAt(i) != ')' || str.charAt(i) != '['
|| str.charAt(i) != ']' || str.charAt(i) != '{'
|| str.charAt(i) != '}') {
System.out.println("invalid string, try again: ");
str = s.nextLine();
}
...}