Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the total number by using this formula, (count/9)*(30/100).

But this is the output I get

Output: 0 . 0

Java
private void CountMatching(Object[] array, Object[] array1) {
        int count = 0;
        double total;
        for (int a = 0; a < array.length; a++) {
            for (int b = 0; b < array1.length; b++) {
                if (array[a] == array1[b]) {
                    count++;
                }
            }
        }
        System.out.println(count);
        total=(count/9)*(30.0/100);
        System.out.println(total);
    }
Posted
Updated 22-Aug-15 21:50pm
v2

Quote:
total=(count/9)*(30.0/100);
In the above line (count/9) is evaluated using the integer division, since both the operands are integers. Change to
Java
total=(count/9.0)*(30.0/100);
in order to obtain the expected result.
 
Share this answer
 
Comments
wseng 23-Aug-15 9:58am    
Thanks a lot !
CPallini 23-Aug-15 10:10am    
You are welcome.
this works..
double count = 0.0d;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900