basically, Ive been asked to write a program that checks how many times a number is apparent in a string and print it out. This is what i have
BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Please enter your string");
String s = input.readLine();
/*System.out.println("Please enter the chracter you are looking for");
char c = (char)input.read();*/
char one = '1';
char two = '2';
char three = '3';
char four = '4';
char five = '5';
char six = '6';
char seven = '7';
char eight = '8';
char nine = '9';
char zero= '0';
int counter = 0;
for( int i=0; i<s.length(); i++ ) {
if( s.charAt(i) == one || s.charAt(i) == two || s.charAt(i) == three || s.charAt(i) == four ||
s.charAt(i) == five || s.charAt(i) == six || s.charAt(i) == seven
|| s.charAt(i) == eight || s.charAt(i) == nine || s.charAt(i) == zero ) {
counter++;
}
}
is there a faster, better way to do this? I tried another way but for this error
Error: The operator || is undefined for the argument type(s) boolean, char