I'm trying to make a program that asks a user for two numbers. I want to determine how many times a certain value appear in the sequence of numbers. For instance, if user entered 10 and 20 the number "1" would appear 9 times. What I am wondering is what condition would I have to set to see how many times the number "1" would appear.
This is what I got so far...
System.out.println("Enter a number: ");
int no1 = scan.nextInt();
System.out.println("Enter a number: ");
int no2 = scan.nextInt();
int i;
int j = 0;
for(i = no1; i <= no2; i++){
if(){ // Some condition here
j++;
}
}
System.out.println(j);
}
Any other tips and tricks on how to make my code efficient would also be greatly appreciated.