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)); } }
1 Antwort
+ 4
because you provide 2 as integer, so division is whole division...
try:
percent = 2.0 / houses * 100;