JavaBeginner#puzzle#operators

What is the output? public class Test { public static void main(String[] args) { System.out.println(10 / 3); System.out.println(10.0 / 3); System.out.println(10 % 3); } }

10 / 3 with two ints performs integer division, truncating the result to 3. 10.0 / 3 uses floating-point division, producing 3.3333333333333335. 10 % 3 is the remainder, 1.

Example
System.out.println(10 / 3);   // 3
System.out.println(10.0 / 3); // 3.3333333333333335
System.out.println(10 % 3);   // 1

Related Questions

1
JavaAdvanced#puzzle#oop

What happens when you compile and run this code? class Parent { static void greet() { System.out.println("Parent"); } } class Child extends Parent { static void greet() { System.out.println("Child"); } } Parent p = new Child(); p.greet();

Open
2
JavaIntermediate#puzzle#arrays

What is the output of this array comparison? int[] a = {1, 2, 3}; int[] b = {1, 2, 3}; System.out.println(a == b); System.out.println(a.equals(b)); System.out.println(Arrays.equals(a, b));

Open
3
JavaAdvanced#puzzle#oop

What does this output? class Base { int x = 10; int getX() { return x; } } class Derived extends Base { int x = 20; int getX() { return x; } } Base obj = new Derived(); System.out.println(obj.x); System.out.println(obj.getX());

Open