I can not understand why in my example below the result is rounded (the answer is 0.0, not 0.1)

public static double addTenPercent(int i) { double x = i/100; return x; } public static void main(String[] args) { System.out.println(addTenPercent(10)); } 

    1 answer 1

    Because with integer division, the result is rounded down to an integer. You need to write double(i)/100 or i/100.0 .