Count Occurances

Run Settings
LanguageJava
Language Version
Run Command
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a number : "); long num = in.nextLong(); System.out.print("Enter a digit : "); int digit = in.nextInt(); int count = 0; long rem; while(num != 0){ rem = num % 10; if(rem == digit){ count++; } num /= 10; } System.out.println(digit + " is occured " + count + " times."); } }
Editor Settings
Theme
Key bindings
Full width
Lines