Certain digit in Java | Ask The Code

Basic Java Programming | Display certain digit in Java | AskTheCode

Problem:

How many of a certain digit is present on a given number.


Input sample:

2·124218

Output Sample:

2


Code:


import java.util.Scanner;

import java.text.DecimalFormat;


public class certain_Digit{

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

DecimalFormat df = new DecimalFormat("#");

float num = scan.nextFloat();


System.out.println(df.format(num));

}

}


1 view0 comments

Recent Posts

See All

"Believe you can and you're halfway there"