To divide in Java, use the slash (
/
) operator like so: 4 / 2
.Here's how you do it:
int fourByTwo = 4 / 2;
double fiveByHalf = 5 / 0.5;
System.out.println(fourByTwo); // 2
System.out.println(fiveByHalf); // 10.0
/
) operator like so: 4 / 2
.Here's how you do it:
int fourByTwo = 4 / 2;
double fiveByHalf = 5 / 0.5;
System.out.println(fourByTwo); // 2
System.out.println(fiveByHalf); // 10.0