Help, Why do I keep getting 0.0 no matter the input? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help, Why do I keep getting 0.0 no matter the input?

https://sololearn.com/coach/4/?ref=app import java.util.*; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int houses = input.nextInt(); double percent; percent = 2 / houses * 100; System.out.print(Math.ceil(percent)); } }

26th Jun 2021, 2:15 AM
Da Russian
Da Russian - avatar
2 Answers
+ 4
because you provide 2 as integer, so division is whole division... try: percent = 2.0 / houses * 100;
26th Jun 2021, 2:22 AM
visph
visph - avatar
0
Show your attempt so we can detect your error
26th Jun 2021, 2:17 AM
Aysha
Aysha - avatar