// accept numbers from 0.1 to 99.9 then count the number of tens, ones, and tenths

import java.io.*;

public class accept99_9 {

    public static void main(String[] args)throws IOException {

        BufferedReader abc=new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter a value: ");
        String input=abc.readLine();
        float v=Float.parseFloat(input);
        float tens=v %100;
        float ones=v %10;
        float tenths=v %10;
        System.out.println("Number of tens: "+tens);
        System.out.println("Number of ones: "+ones);
        System.out.println("Number of tenths: "+tenths);
        System.exit(0);
    }
}

How will i come up with an output like these?

example....
Enter a value: 12.3
Number of tens: 1
Number of ones: 2
Number of tenths: 3

thanks........

you're looking for ints, and the last one must be mutiplied by 10 other wise the int value will always be 0 (obviously) and the first one divided by ten or it will be e.g. 10 instead of 1.

int tens=(int) ((v / 10) % 10);
int ones=(int) (v % 10);
int tenths=(int) ((v * 10) % 10);

........wow........it worked......thanks a lot for your help sir masijade.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.