This question has already been answered:
public class Solution { public static double addTenPercent(int i) { double c = i * 10 / 100; double p = i + c; return p; } public static void main(String[] args) { System.out.println(addTenPercent(9)); } } This question has already been answered:
public class Solution { public static double addTenPercent(int i) { double c = i * 10 / 100; double p = i + c; return p; } public static void main(String[] args) { System.out.println(addTenPercent(9)); } } A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
If you want to get a double result, then in the expression you should use the corresponding values (at least one):
public static double addTenPercent(int i) { double c = i * 10.0 / 100; double p = i + c; return p; } Otherwise, the expression i * 10 / 100 10/100 is first considered working with integers, and only after receiving the result, is it casting to double type.
Source: https://ru.stackoverflow.com/questions/696424/
All Articles