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)); } } 

Reported as a duplicate by participants Alexey Shimansky , tutankhamun , aleksandr barakin , Cheg , Nick Volynkin Jul 23 '17 at 2:35 .

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 .

  • one
    And what is the number of nnnnado? - Vlad Vetrov
  • Due to the given number add 10% of this number - Andrew
  • That is, it should be 9.9 - Andrew
  • you can do addTenPercent like this (double i) - Vlad Vetrov
  • Not not, that's the joke - Andrew

1 answer 1

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.

  • Made 100.0 - earned, I don’t know why - Andrew
  • Can you say why? - Andrew
  • The last sentence in the answer :) - Alex Chermenin