When you divide two intvalues, the result is an integer value - Java Language Basics

Java examples for Language Basics:int

Introduction

even if you assign it to a double variable. For example:

Demo Code

public class Main {
  public static void main(String[] args) {
    int a = 21, b = 6;
    double answer = a / b;   // answer = 3.0

    System.out.println(answer);//  w ww .  j a va 2 s .c o m
  }
}

Related Tutorials