Skip to content

Instantly share code, notes, and snippets.

@ThanawatMas
Last active October 31, 2018 02:17
Show Gist options
  • Save ThanawatMas/ce25b8d6ad810338035aca1ccd3ff665 to your computer and use it in GitHub Desktop.
Save ThanawatMas/ce25b8d6ad810338035aca1ccd3ff665 to your computer and use it in GitHub Desktop.
Different between divide by int, and divide by double
public class DivideExample {
public static void main(String[] args) {
int a = 9;
int b = 2;
int c = 5;
double average1 = (a+b+c) / 3;
System.out.println("average1 of a+b+c = " + average1);
int x = 9;
int y = 2;
int z = 5;
double average2 = (x+y+z) / 3.0;
System.out.println("average2 of x+y+z = " + average2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment